Created
June 8, 2019 22:10
-
-
Save cevr/f76a7558eb82aee6574df675b34709bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function App() { | |
const fetchTodos = useActions(actions => actions.fetchTodos); | |
useEffect(() => { | |
fetchTodos(); | |
}, [fetchTodos]); | |
return ( | |
<div> | |
<h1 style={{ margin: 0 }}>Todo</h1> | |
<Todos /> | |
<AddTodo /> | |
</div> | |
); | |
} |
Ok, thank you very much for clearing my mind. I see now that it was intentional.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was more to appease the react-hooks eslint rule 😅
Since
fetchTodos
is guaranteed to remain constant, it will only run once throughout the lifecycle of this component.On the first render, the effect has nothing to compare itself to so it will run the
fetchTodos
.On every subsequent render, it will not fire due to
fetchTodos
being identical.So in practice, this is the same as doing: