首页 > 其他分享 >react hooks 中useContext的使用

react hooks 中useContext的使用

时间:2023-09-07 14:24:06浏览次数:34  
标签:count const hooks CountContext react useContext import

父组件中:

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

相关文章