donavon/use-persisted-state

Development issue

entrptaher opened this issue · 3 comments

Using the package on development mode from the git repo does not work.

  • Works: yarn run dev. It does not throw any error on console.
  • Works: yarn run test. It does not throw any error on console.
    It means it's built properly, right?

But,

  • Works: import createPersistedState from 'use-persisted-state'.
  • Doesn't Work: import createPersistedState from './use-persisted-state'. It throws the following error,
Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)
  1 | import createPersistedState from './use-persisted-state';
  2 | const useCounterState = createPersistedState('count');
  3 | 
> 4 | const useCounter = initialCount => {
    |                                   ^  5 |   const [count, setCount] = useCounterState(initialCount);
  6 | 
  7 |   return {

I found no contribution guide so maybe I did not do it the right way.

I guess I'm not sure exactly what you are trying to do. What happens if you replace useCounterState above with setState? If it's producing the same error (it should) then you are calling the useCounter hook from outside of a component.

I cloned your repo, built it and simply changed,

import createPersistedState from 'use-persisted-state'; 

to

import createPersistedState from './use-persisted-state';

and the error happens. It works perfectly fine if I use the NPM version.

It only happens when I git clone your repo.

How do I contribute if I cannot run it off of npm? :D

sounds like you need to correct the path you are using to match the repository structure (which looks standard):

import createPersistedState from './use-persisted-state/src'