父组件中:
import React ,{useState, createContext} from 'react' import './App.css'; import ChildOne from './components/ChildOne'; import ChildTwo from './components/ChildTwo'; export const CountContext = createContext() function App() { const [count ,setCount] = useState(0) return ( <div className="App"> <h3>这是一个页面的头部标题</h3> <div> <div> {count}</div> <button onClick={()=>{setCount(count+1)}}>点赞 标签:count,const,hooks,CountContext,react,useContext,import From: https://www.cnblogs.com/anna001/p/17684765.html