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

Mention gotchas regarding createMutable #149

Open
trusktr opened this issue May 24, 2022 · 1 comment
Open

Mention gotchas regarding createMutable #149

trusktr opened this issue May 24, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@trusktr
Copy link
Contributor

trusktr commented May 24, 2022

@ryansolid mentioned that there are some gotchas with mutables, and we should document them. They aren't mentioned.

From discord:

there are just so many more considerations mutables bring and I didn't really design for them since i never use them for anything.
I probably should have just left them to 3rd party

I believe createMutable is an excellent API. I use it for internal state in my components because the dev experience is far better than having to write setter calls to modify stores made with createStore.

The majority of the time, we do not need read/write segregation for a component's internal state, so writing the following is simpler:

function MyCounter() {
  const state = createMutable({
    count: 0
  })

  setInterval(() => state.count++, 1000)

  return <div>Count: {state.count}</div>
}

I haven't ran into any issues with mutables yet, and I've been using them exclusively for component state in an app at work. Knowing what issues exist, and documenting them, will go a long way.

@trusktr
Copy link
Contributor Author

trusktr commented May 24, 2022

Here's an unexpected infinite reactivity loop issue with mutables that gawlk mentioned:

https://playground.solidjs.com/?hash=334307390&version=1.4.1

EDIT: simpler version:

https://playground.solidjs.com/?hash=-349349508&version=1.4.1

with a workaround in the child component using untrack by @edemaine: https://playground.solidjs.com/?hash=-768089954&version=1.4.1

@orenelbaum orenelbaum added the documentation Improvements or additions to documentation label Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants