WebReflection / uland

A µhtml take at neverland
ISC License
108 stars 2 forks source link

[Help] Usage of useContext is rendering more than expected. #4

Closed djalmajr closed 4 years ago

djalmajr commented 4 years ago

Here I am again 😅. This time, I am having problem in how to make my Todo component been called only when his attributes have changed... I thing that it's rendering more than expected (maybe, something related to Context.provide). What am I missing?

perf-problem

P.S: I have rewrite this app from react/preact to uland and I would like to know how difficult is to port from react do uland... In react/preact -- with two records and without using memo -- the console.log is called twice, only. With uland, the console.log is called six times.

Example code: https://codepen.io/djalmajr/pen/GRZgzJY

Thanks in advance!

WebReflection commented 4 years ago

The context provider is different in uland/neverland, as you are the one in charge of providing outside the augmented cycle a new value, i.e. on DOM change event.

If you provide states within a component, you are in some sort of "infinite loop" state, as you're providing values while updating values, and since these are also always different in your case, you keep invoking the stack per each provider.

Some way to solve this is to provide only on the top-most level, as that would do the whole dance for you once, instead of N times.

That being said, I'm on vacation this week, so I won't be on my laptop much, hope you can find better examples within neverland documentation or via checking previous discussions around this.

Here a context example: https://codepen.io/WebReflection/pen/QYOZZE?editors=0010