RubenVerborgh / Solid-React-Components

Core React components for building your own Solid components and apps
https://rubenverborgh.github.io/Solid-React-Components/
MIT License
118 stars 21 forks source link

Make useLDflex support LDflex paths #15

Open RubenVerborgh opened 5 years ago

RubenVerborgh commented 5 years ago

Currently, we can call useLDflex with LDflex strings. For example:

const image = useLDflex('user.image');

However, LDflex paths should also be possible (as is the case with the higher-order-component evaluateExpressions):

const image = useLDflex(solid.data.user.image);

The above will currently not work, because solid.data.user.image will evaluate to a new value every time it is called, triggering infinite rerenders.

This would work:

const promise = solid.data.user.image;
function render() {
  const image = useLDflex(promise);
}

but that obviously creates other problems.

What we probably want is a caching feature in LDflex, such that the same paths trigger the same values (until, for instance, the cache is cleared).

Alternatively, LDflex could generate an internal key, and that key is used to conditionally trigger useEffect.