父组件
import {createContext} from 'react';
import SearchPart from './searchpart'; //引入子组件
export const FatherContext = createContext();
function AAA(){
const [AA, setAA] = useState(Array);
const BB= useSelector(state => state.BB.data);
.....
return (
<div>
<FatherContext.Provider
value={{
AAA: AA,
BBB: BB,
}}
>
<SearchPart/> //子组件
</FatherContext.Provider>
<div>
)
.....
}
子组件
import {useContext} from 'react';
import { FatherContext } from './index';
function SearchPart(){
const AAA=useContext(FatherContext).AAA;
const BBB=useContext(FatherContext).BBB;
......
}
就可以直接使用了
新手小白,如果有帮助到你,能点个赞嘛!!谢谢!!!
版权声明:本文为qq_40044912原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。