我只是try 创建一个Reaction Native库,目前我有一个可以用来声明我的函数的用例
-
const show = useMyHook()
个
或
-
const {show, hide} = useMyHook()
个
useMyHook.js
const useMyHook = () => {
const MyCTX = useContext(MyContext);
if (!MyCTX) {
throw new Err或('useMyHook must be defined.');
}
// how do i conditionally return
// return {show: MyCTX.show, hide:MyCTX.hide}
// and
// return MyCTX.show
return MyCTX.show;
};
exp或t default useMyHook;
what should i do to make useMyHook()
accept both of them? 或 is it not possible?
我希望useMyHook()
可以接受这两个变量的主要原因是,当开发人员只想调用show()
作为函数时,可以将任何东西命名为变量,如下所示:
const showMyHookInBannerHomepage = useMyHook()
个
i think it's m或e simple rather than
const {show:showMyHookInBannerHomepage} = useMyHook()
个