我Property 'toggleAuthError' does not exist on type 'IntrinsicAttributes & InterfaceProps'.ts(2322)在尝试将函数从上下文提供程序传递到组件时遇到 Typescript 错误。
上下文提供者是
interface InterfaceProps {
children?: any;
}
interface InterfaceState {
error: any;
toggleAuthError: any;
}
const GlobalContext = createContext({
error: null,
toggleAuthError: () => {}
});
export class GlobalProvider extends React.Component<InterfaceProps, InterfaceState> {
public toggleAuthError = ({ authError }: any) => {
this.setState({ error: authError });
};
public state = {
error: null,
toggleAuthError: this.toggleAuthError
};
public render() {
console.log(this.state);
const { children } = this.props;
return <GlobalContext.Provider value={this.state as any}>{children}</GlobalContext.Provider>;
}
}
export const GlobalConsumer = GlobalContext.Consumer;
我访问该值的组件是
const SignInPageBase = () => (
<GlobalProvider>
{({ toggleAuthError }: any) => (
<Form toggleAuthError={toggleAuthError} />
)}
</GlobalProvider>
);
错误显示在import组件上Form。
是什么导致了这个错误,我该如何解决?我有许多类似的组件,没有这个问题。
白板的微信
桃花长相依
相关分类