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

Does createStore make any sense at all? #2391

Open
MateuszDev96 opened this issue Dec 30, 2024 Discussed in #2390 · 0 comments
Open

Does createStore make any sense at all? #2391

MateuszDev96 opened this issue Dec 30, 2024 Discussed in #2390 · 0 comments

Comments

@MateuszDev96
Copy link

Discussed in #2390

Originally posted by MateuszDev96 December 30, 2024
Personally, I don't use createStore in my project even for more complex data because there is a bit too much ‘magic’ there for me and using createSignal I can handle react-js without any problems and I already explain what I think about all this

Example from react-js

const [complexData, setComplexData] = useState({
  myValue: ‘my shallow value’,
  deep: {
    nested: {
      value: ‘my nested value’
    }
  }
})

const myValue = useMemo(() => complexData.myValue, [complexData.myValue]) // logs ‘my shallow value’
const deepNestedValue = useMemo(() => complexData.deep.nested.value, [complexData.deep.nested.value]) // logs ‘my nested value’

React.useEffect(() => [
  // run when `myValue` or `deepNestedValue` changed
], [myValue, deepNestedValue])

and react handles the reactivity after the setter is called

Example solid-js

const [complexData, setComplexData] = createSignal({
  myValue: ‘my shallow value’,
  deep: {
    nested: {
      value: ‘my nested value’
    }
  }
})

const myValue = createMemo(() => complexData().myValue) // logs ‘my shallow value’
const deepNestedValue = createMemo(() => complexData().deep.nested.value) // logs ‘my nested value’

createEffect(() => {
  myValue()
  deepNestedValue()
  // run when `myValue` or `deepNestedValue` changed
})

I use useMemo or createMemo which basically gives the same results in both solutions and I don't understand why we need to set Proxy

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

No branches or pull requests

1 participant