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

[request] Can we use react-model within taro? #107

Open
leecade opened this issue Jun 12, 2019 · 2 comments
Open

[request] Can we use react-model within taro? #107

leecade opened this issue Jun 12, 2019 · 2 comments
Labels
✨Feature Request New feature or request ⏱help wanted Extra attention is needed
Milestone

Comments

@leecade
Copy link
Contributor

leecade commented Jun 12, 2019

via: https://nervjs.github.io/taro/docs/hooks.html

@ArrayZoneYour ArrayZoneYour added the ⏱help wanted Extra attention is needed label Jun 23, 2019
@ArrayZoneYour
Copy link
Contributor

It requires a more generic implementation of useStore.

src/index.tsx

import { PureComponent, useEffect, useState } from 'react'
//                         👇          👇
//             import { useEffect, useState } from '@tarojs/taro'

// .......

const useStore = (modelName: string, depActions?: string[]) => {
  const setState = useState(Global.State[modelName])[1]

  useEffect(() => {
    Global.uid += 1
    const hash = '' + Global.uid
    if (!Global.Setter.functionSetter[modelName]) {
      Global.Setter.functionSetter[modelName] = {}
    }
    Global.Setter.functionSetter[modelName][hash] = { setState, depActions }
    return function cleanup() {
      delete Global.Setter.functionSetter[modelName][hash]
    }
  }, [])

  const updaters = getActions(modelName, { setState, type: 'function' })
  return [getState(modelName), updaters]
}

@ArrayZoneYour ArrayZoneYour added the ✨Feature Request New feature or request label Jun 23, 2019
@ArrayZoneYour ArrayZoneYour added this to the v3.0 milestone Jun 23, 2019
@kyleslight
Copy link
Collaborator

I have implemented a lib for Taro, see https://github.com/kyleslight/react-model-taro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨Feature Request New feature or request ⏱help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants