More complex examples or good/bad practices documented
See original GitHub issueHey! Awesome work! I hope it’s gonna be a part of React 🤞.
To be precise: I’m not raising issue, rather feature request - could you please extend documentation or add more complex examples? Especially part about good/bad practices. For example how to access function/objects stored in context because those must have same reference in order to skip update. Example - component is getting function from context:
const addListener = useContextSelector(
ListenerContext,
listeners => listeners.addListener
)
Provider looks like:
const [listeners, setListeners] = useState([])
const [state, setState] = useState({}) // some other state
const addListener = (listener) => {
// some complex logic
setListeners(newListeners)
}
const state = {
state,
addListener,
}
return (
<Provider value={state}>
{children}
</Provider>
)
Therefore as compare condition is:
(ref.current.v === nextValue || Object.is(ref.current.s, ref.current.f(nextValue)))
Update will be triggered. However it might be fixed by useRef:
const { current: addListener } = useRef((listener) => {
// some complex logic
setListener(newListeners)
})
I think there are more examples of how to use/how to not use this hook and it might be helpful to document it.
Cheers!
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
14 Examples of Documentation Mistakes You Are Making
When it comes to doing something right, it sometimes helps to see how it's done wrong. So here are 13 examples of bad...
Read more >Eight Common Database Design Bad Practices - Toptal
In this article, Toptal Freelance Software Engineer Fernando Martinez discusses some of the most common database design bad practices and how to avoid...
Read more >Process Documentation: Definition & Best Practices - Helpjuice
Process documentation maps out an ideal way of completing a workflow in your business. Here's everything you need to know and how to...
Read more >Putting comments in code: the good, the bad, and the ugly.
“Good code is self-documenting.” In 20+ years of writing code for a living, this is the one phrase I've heard the most. It's...
Read more >Best practices for writing code comments - Stack Overflow Blog
The most infamous comment in the Unix source code is “You are not ... above examples have shown that comments don't excuse or...
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
I have converted to my own event emitter for the React warning and performance when using 1000+ useContextSelectors. This also gave some size advantages for me, I’ll answer with how I used it here tomorrow.
Closing this. Please open a new issue for further discussion.