发送数据时,是否未显示未定义的useContext?发送数据时,发送数据时不显示未定义的useContext,发送数据时不显示未定义的useContext,也不显示未定义的useContext。
Card.jsx
import React from 'react'
import Button from 'react-bootstrap/Button';
import Card from 'react-bootstrap/Card';
import { Link } from 'react-router-dom';
export
在我自己的代码中,我试图通过将react-router的useHistory添加到imports中来使用它:
import {BrowserRouter as Router, Link, Route, Switch, useHistory} from "react-router-dom";
然后用它在我的App()函数上定义一个变量:
let history = useHistory();
当我这样做的时候,我得到了错误:
TypeError: useContext(...) is undefined
来自react-router的hooks.js,具体行是:
return u
我使用useContext和useReducer来管理应用程序状态。
下面是代码片段:
//ReducerProvider.tsx
type ContextProviderType = {
state: StateInterface,
dispatch: React.Dispatch<ActionInterface>
}
type CreateContextType = ContextProviderType | string; // i am passing to the createContext either the ContextProvide
我的上下文API提供程序文件(Exp文件)
import react form 'react';
import {createContext} from "react";
export const ContextforFile = createContext();
export function ContextData(props){
let rdata=props.data
return(
<>
<p>{rdata}</p> //I am able to Get the Data here NO ISS