react hooks

import { View, Text, Button } from 'react-native'
import React, {useContext,useEffect, useState,useReducer} from 'react'

const My = () => {
    const initState = {cout:0}
    const reducer =(state,action)=>{
console.log('77777777777777777777777');
console.log(state);
if (action.type == 'add') {
    console.log(state);
    return {cout:state.cout +=1}
}
    }
    const [state,dispatch] = useReducer(reducer,initState)
    const Context = React.createContext({name:'122',title:'12345'})
    const xdx = useContext(Context)
    const [cout,setCout] = useState(2)
    // useEffect(()=>{
    //     setCout(8)
    // })
  return (
    <View>
      <Text>My{xdx.name}=={cout}=={state.cout}</Text>
      <Button title='点击' onPress={()=>{dispatch({type:'add'})}} />
    </View>
  )
}

export default My

 

posted @ 2022-08-17 15:42  zjxgdq  阅读(21)  评论(0编辑  收藏  举报