How to force a re-render?
Closed this issue · 2 comments
pbastowski commented
Nice library, thanks for creating it.
I want to re-render my component based on some condition, such as an updated in an imported reactive store. In lit-element I would call this.requestUpdate()
to do that.
How do I request an update (re-render) in fuco?
wtnbass commented
You can use a reducer that always returns a different value with useReducer
to force update.
Here is an example:
const [, forceUpdate] = useReducer<number, void>(x => x + 1, 0);
function subscribe() {
forceUpdate();
}
Reference
https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
pbastowski commented
Thanks, that worked very well.