preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.78k stars 93 forks source link

Why my ComponentDidMount lifecycle are trigger twice ? #329

Closed dc198689 closed 1 year ago

dc198689 commented 1 year ago

Hi, I have a issue and hope someone to help fix.

My useEffect (ComponentDidMount) are trigger twice when page load !! 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.

` 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; `

JoviDeCroock commented 1 year ago

Your effect had no dependencies and you might have strict mode on

dc198689 commented 1 year ago

@JoviDeCroock 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.

I pretty sure I have not use the StrictMode of my react version

rschristian commented 1 year ago

Going to close this out. As mentioned, you probably have strict mode on which would cause this behavior.