mobxjs / mobx-vue-lite

Lightweight Vue 3 bindings for MobX based on Composition API.
MIT License
72 stars 3 forks source link

Mobx and memo #130

Closed untlsn closed 2 years ago

untlsn commented 2 years ago

Mobx only works when using the observator without memo.

// Work but deprecated
const Button = () => useObserver(() => {
    const count = useLocalObservable(() => ({
      value: 0,
    }))

    return (
      <button onClick={action(() => {
        count.value++;
      })}>{count.value}</button>
    )
  }
)
// Dont work
const Button = React.memo(() => useObserver(() => {
    const count = useLocalObservable(() => ({
      value: 0,
    }))

    return (
      <button onClick={action(() => {
        count.value++;
      })}>{count.value}</button>
    )
  }
))

const Button = observer(() => {
    const count = useLocalObservable(() => ({
      value: 0,
    }))

    return (
      <button onClick={action(() => {
        count.value++;
      })}>{count.value}</button>
    )
  }
)

Additionally, it gets an unusual output

(props) => { return component(Object.values(props)); }
iChenLei commented 2 years ago

Maybe this repository is for you https://github.com/mobxjs/mobx