🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

react-model-taro

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-model-taro

The Hooks State management library for Taro

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

react-model-taro

The Hooks State management library for Taro

Requirement: Taro 1.3.0 and above, from this version you can use Hooks in Taro

Quick Usage

In your empty Taro Project Components:

import Taro, { useState } from '@tarojs/taro'
import { View, Input } from '@tarojs/components'

const Index = () => {
  return (
    <View>
      Content Here...
    </View>
  )
}

Index.config = {
  navigationBarTitleText: 'React Model'
}

export default Index

Use store from react-model-taro:

import { Model } from 'react-model-taro'

// define model
const Todo = {
  state: {
    items: ['Install react-model', 'Read github docs', 'Build App']
  },
  actions: {
    add: (todo, { state }) => {
      state.items.push(todo)

      return {
        items: state.items
      }
    }
  }
}

// Model Register
const { useStore } = Model(Todo)

const [{ items }] = useStore()

...
<View>
  {items.map((item, index) => {
    return <View key={index}>{item}</View>
  })}
</View>

Now your state is reactive!

More about react-model

See ref: https://github.com/byte-fe/react-model

Keywords

react

FAQs

Package last updated on 03 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts