forceUpdate
A forceUpdate is a function which calls a render function and sends a result to the user.
This function is called when
- component gets initialized;
forceUpdateis manually called inside a script.
Consider a component with button which on click increases a counter:
src/components/counter.tsx
export const component: DraymanComponent = async ({ forceUpdate }) => { let count = 0;
return () => { return ( <> <h3>{count}</h3> <button onclick={async () => { count++; await forceUpdate(); }} > +1 </button> </> ); };};User sees current value of counter because every time it increases, a forceUpdate function gets called.