hook2hoc
Typesafe converter of React hooks to React hocs 🤓
What and why
Main purpose of this project is making integration of hooks to existing project much easier.
This is an automate and type-safe converter of React hooks to React HOCs. Just move your logic to hook, create a HOC for compatability and go.
Installation
npm install hook2hoc
Usage
The main purpose of this project is to easily reuse your custom hooks logic in class components.
{ const value setValue = React; return value ;} Component ... { const value onChange = thispropsformInput; return <input = = />; } "formInput" useFormInputClassComponent// or with default args"formInput" useFormInput "initalValue"ClassComponent
Dynamic props
It is also possible to pass arguments to your hooks directly from the props. Just use function instead of array in last argument.
ClassComponent
Type safety
This helper was created with static typing in mind. For typescript users it will infer the types properly. One thing is required for dynamic props
; // tuple required for strict parameters type casting WithHook someAnotherProp="required as well" /