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
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/16595478.html

浙公网安备 33010602011771号