score:19

Accepted answer

I believe you should use the hooks inside the HOC:

const WithState = (Component) => {
  const WithStateComponent = () => {
    const [state, dispatch] = useState(0);
    return <Component state={state} dispatch={dispatch} />;
  }
  return WithStateComponent;
}

score:4

Inspired by Rafael Souza's answer, you can make it even cleaner with:

const WithState = (Component) => {
  return () => {
    const [state, dispatch] = useState(0);
    return <Component state={state} dispatch={dispatch} />
  }
}

Related Query

More Query from same tag