Cannot read properties of null (reading 'useRef') when use my own library

352 views Asked by At

I have created my own library with a small react component. That component uses react hooks: useCallback, useEffect, useMemo, useRef, useState. (https://github.com/Pabrick/react-carnival)

When I use it in another project I get the error:

Cannot read properties of null (reading 'useRef')
TypeError: Cannot read properties of null (reading 'useRef')
    at s.exports.f.useRef (http://localhost:3000/static/js/bundle.js:42272:16)
    at pn (http://localhost:3000/static/js/bundle.js:43986:13)
    at renderWithHooks (http://localhost:3000/static/js/bundle.js:20107:22)
    at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:23393:17)
    at beginWork (http://localhost:3000/static/js/bundle.js:24689:20)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:9699:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:9743:20)
    at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:9800:35)
    at beginWork$1 (http://localhost:3000/static/js/bundle.js:29674:11)
    at performUnitOfWork (http://localhost:3000/static/js/bundle.js:28921:16)

What I am missing?

I have checked that both (library and project) uses the same react versions. I have tryed moving some devendecies from devDependecies to dependecies. But nothing works.

1

There are 1 answers

1
Pabrick On

The problem was that the library wasn't exported correctly. I have changed my rollup config and that made it work.