useContext 解决函数父子组件传值
1在父组件外部定义变量A创建上下文,2在父组件使用变量A <子组件/> ,3.在子组件中创建变量使用useContext(),把定义变量返回出去
import React, { useState,createContext,useContext } from 'react'
let contContext = createContext()
// let ageContest = createContext()
const SonContext =()=>{
// let age = 19
let count = useContext(contContext)
return(
<>
{count}
>
)
}
const UseContext = ()=>{
const [count ,usecount] = useState(0)
return(
{count}
)
}
export default UseContext