import React, { FC, Dispatch, SetStateAction, createContext, useState } from "react";
interface Data {
foo: string;
}
type SetData = Dispatch<SetStateAction<Data>>;
export const FooContext = createContext<Data>({ foo: "" });
export const SetFooContext = createContext<SetData>(() => Promise.resolve());
interface Props {
bar: number;
}
export const Provider: FC<Props> = ({ children }) => {
const [data, setData] = useState<Data>({ foo: "" });
return (
<FooContext.Provider value={data}>
<SetFooContext.Provider value={setData}>{children}</SetFooContext.Provider>
</FooContext.Provider>
);
};
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme