troch / reinspect

Use redux devtools to inspect useState and useReducer :mag_right:
MIT License
424 stars 24 forks source link

useReducer's type definition invalid: can't supply id as 3rd param #7

Closed 0xdevalias closed 5 years ago

0xdevalias commented 5 years ago

I'm not 100% if this is a bug, or a me problem, but it seems that your TS definitions imply that i can call useReducer with 3 params, and have it take the id from the 3rd param: node_modules/reinspect/types/useReducer.d.ts

export declare function useReducer<R extends Reducer<any, any>>(reducer: R, initialState: ReducerState<R>, id?: string | number): [ReducerState<R>, Dispatch<ReducerAction<R>>];

But when running the code, and debugging, it looks like that isn't actually the case: image

I assume the current 'solution'/workaround is what is referred to in the README, namely:

If no id is supplied, the hook won't be connected to dev tools. You can use identity function (state => state) as 3rd parameter to mock lazy initialization.

If that is intended as the only way to use this, then updating the type defs to disallow passing id as the 3rd param would be great.

0xdevalias commented 5 years ago

Of course I realise it's a bug in my own code just after I make an issue for it.. seems the variable I was passing as the identifier was actually undefined due to my own bug, so the type definitions seem to work correctly passing id as the 3rd or 4th param.