You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the following code to create the EditorContext:
exportconstEditorContext=createContext<EditorContextValues>(defaultContextValues);exportdefaultfunctionEditorProvider({ children }: {children: ReactNode}){const_preferences=useStateEx(EditorPreferencesDefaults);const_states=useStateEx(EditorStatesDefaults);// ...return(<EditorContext.Providervalue={value}>{children}</EditorContext.Provider>);}
And below is a wrapper for useContext:
exporttypeEditorContextSelected<T>=T&Pick<EditorContextValues,"onContextSave"|"onContextUpdate"|"onContextUpdateDelay">;exportdefaultfunctionuseEditorContextSelector<selectedextendsobject>(selector: (value: EditorContextValues)=>selected) : EditorContextSelected<selected>{constcontext=useContextSelector(EditorContext,(v)=>{constvalue=v;constselectorResult=selector(value);return{
...selectorResult,onContextSave: value.onContextSave,onContextUpdate: value.onContextUpdate,onContextUpdateDelay: value.onContextUpdateDelay,}});if(!context)thrownewError("useThemeSettingsContext must be use inside SettingsProvider");returncontext;};
But then I use the function useEditorContextSelector like this:
Uncaught
TypeError: Cannot read properties of undefined (reading 'viewport3d')
at viewport-3d.tsx:48:40
at use-context.ts:18:32
at useContextSelector (index.js:123:22)
at useEditorContextSelector (use-context.ts:10:21)
at Viewport3DScene (viewport-3d.tsx:44:20)
at renderWithHooks (react-reconciler.development.js:7363:18)
at mountIndeterminateComponent (react-reconciler.development.js:12327:13)
at beginWork (react-reconciler.development.js:13831:16)
at HTMLUnknownElement.callCallback2 (react-reconciler.development.js:14219:14)
at Object.invokeGuardedCallbackDev (react-reconciler.development.js:14268:16)
After some digging, I found out that the argument v is not the type of EditorContextValues which I want.
It looks like this when I use console.log to inspect it:
I don't know whether this is an internal bug of this package, or it's caused by my incorrect usage.
Has anybody got the same problem? I need this to be fixed as soon as possible.
Thanks!
EDIT 05-19-2024
I'm using @react-three/fiber package on my project. And this issue only appears when I invoke useEditorContextSelector inside a three-fiber element. Invoking it inside a normal react component will not cause this issue.
The text was updated successfully, but these errors were encountered:
NotYoojun
changed the title
useContextSelector(.., selector: (v) => ...) The v is not the valid context type
In useContextSelector(.., selector: (v) => ...) the argument v is not the valid context value type
May 19, 2024
Hi there,
I use the following code to create the EditorContext:
And below is a wrapper for useContext:
But then I use the function useEditorContextSelector like this:
I got this error in my console:
After some digging, I found out that the argument
v
is not the type of EditorContextValues which I want.It looks like this when I use console.log to inspect it:
I don't know whether this is an internal bug of this package, or it's caused by my incorrect usage.
Has anybody got the same problem? I need this to be fixed as soon as possible.
Thanks!
EDIT 05-19-2024
I'm using @react-three/fiber package on my project. And this issue only appears when I invoke useEditorContextSelector inside a three-fiber element. Invoking it inside a normal react component will not cause this issue.
The text was updated successfully, but these errors were encountered: