Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: directive $observe to wrap component in a Memo #402

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

misaeldossantos
Copy link

Hi, I created a babel plugin to automatically wrap components in a just by adding the $observe directive to any jsx tag where you want to observe (I originally created it for mobx, then I adapted it for legend state, it worked the same way).

Example:

<div $observe>Count: {state$.count.get()}</div>

Babel transforms it to

<Memo>{() => <div>Count: {state$.count.get()}</div>}</Memo>

It is identical to the plugin that already exists (https://legendapp.com/open-source/state/v3/react/fine-grained-reactivity/#optionally-add-the-babel-plugin), but without needing to wrap the components in a Memo, just adding a new prop to the component ($observe)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant