I am using @preact/signals-react
to integrate my react
project.
I have an issue that need a fix.
P.S I found that if I removed the import { signal } from '@preact/signals-react'
, thats work for me. I want to use @preact/signals-react
tools.
My Environment
- React v16.8.6
- @preact/signals-react v1.2.2
My Code
import React, { useEffect } from 'react';
import { signal } from '@preact/signals-react';
const Scenes = (props) => {
useEffect(() => {
console.log('ComponentDidMount'); // Trigger Twice !!
}, []);
return <div>Hello</div>;
}
export default Scenes;
3
Answers
If you don’t use dependency array,
useEffect
will run in every render.if you want to render once keep dependency array empty.
You need to understand useEffect properly, it takes two arguments.
First one is a callback function and other one is dependency array. Whatever you put in the dependency array is the checkbox to check when to render it again.
Learn more here – https://blog.bitsrc.io/understanding-dependencies-in-useeffect-7afd4df37c96?gi=41a7917490c8
StrictMode is a development tool that renders components twice, with the purpose of detecting any issues with your code and alerting you about them. This feature is particularly useful during development.
If you are using StrictMode in your application but cannot remember explicitly enabling it, it is likely because you used a tool like create-react-app to set up your application, which automatically enables StrictMode by default.
you might find that your main app is wrapped by <React.StrictMode> in your index.js file:
you can remove the strict mode by
Strict mode is not enabled in production