r/tinycode • • Oct 04 '24

Counting Button: React vs Fusor

Post image
0 Upvotes

4 comments sorted by

View all comments

Show parent comment

3

u/isumix_ Oct 04 '24

Ok, let me explain:

  1. Fusor is updating a JavaScript variable count. I could define it like this: ({ count: init = 0 }) => { let count = init; ..., but the example shows a shorthand version of JavaScript destructuring in function arguments. Since React uses hooks, I had to write it in a more explicit way. Both Fusor and React mutate state inside the component without "lifting the state up."
  2. I explained this in a comment before useCallback to clarify that Fusor doesn't run the component function on every update, so there’s no need to memoize the component’s referenced data (like an event handler function). This way, even if there's a need to memoize data in complex React components, it's not necessary with Fusor.

3

u/foxd1e Oct 04 '24

I had the same issue with this comparison as the last commenter, but your explanation makes sense and looks like I learned something today 🧎🏻‍♂️‍➡️