a little confused about setproject hooks code
See original GitHub issueHi
i got little confused about the follow code
export const useProjects = () => {
const [projects, setProjects] = useState([]);
useEffect(() => {
firebase
.firestore()
.collection('projects')
.where('userId', '==', 'jlIFXIwyAL3tzHMtzRbw')
.orderBy('projectId')
.get()
.then(snapshot => {
const allProjects = snapshot.docs.map(project => ({
...project.data(),
docId: project.id,
}));
if (JSON.stringify(allProjects) !== JSON.stringify(projects)) {
setProjects(allProjects);
}
});
}, [projects]);
return { projects, setProjects };
};
i thought, if component calls setProject, the hooks will update projects, and the UI will got updated. after that, the effect will got fired, which will update the UI again.
should that reading from firebase just get called in app mounting time, and when component calls setProject, we just need to save it to firebase.
sorry for the poor english, the about maybe seems a little rude, but i am not meaning it
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Introducing Hooks - React
Classes confuse both people and machines. In addition to making code reuse and code organization more difficult, we've found that classes can be...
Read more >Understanding common frustrations with React Hooks
React Hooks can be frustrating despite their popularity and widespread use. Learn about some of the drawbacks to using React Hooks.
Read more >Confused with rules · Issue #18 · Gelio/tslint-react-hooks
I'm confused with some rules. ... My code is w... ... Hooks can only be used inside function components and custom hooks.
Read more >React hook confusion - Stack Overflow
Here a little mock up of your code which seems to do whats expected, so I would check the return value of your...
Read more >Why hooks are the best thing to happen to React
Class components have always been a little cumbersome and confusing, especially as it makes state management and code reuse look so much ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This solves the RErendering as Stringify conditions work only when sequence is maintained, firestore is Sending data in random order at times, So avoid spread operaetor here would save 50k firebase calls for you.
Something is causing it to render projects again and again is there a possibility of circular dependency here