【发布时间】:2021-12-01 19:21:18
【问题描述】:
我编写了一个 toast 上下文并将整个项目包装在 toast 提供程序中。如果我的某个组件需要使用 toast,它会调用
function Component() {
const toast = useToast();
toast.success("")
...
}
有没有办法直接导入 toast 而不必在单个组件上调用 useToast() 如下?
import { toast } from "./toast-provider.tsx"
function Component() {
toast.success("")
...
}
【问题讨论】:
标签: reactjs react-context react-functional-component