react-use icon indicating copy to clipboard operation
react-use copied to clipboard

Change some dependencies to `peerDependencies` to use them in different applications

Open meluiz opened this issue 1 year ago • 4 comments

What is the current behavior? I am currently receiving an error when using react-use in React Native applications.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

  1. yarn add react-use
  2. yarn start

What is the expected behavior?

It is expected that some hooks, which rely exclusively on the browser to run, should treat their dependencies as peerDependencies and make it optional to download them for use.

An example I can mention is useCss, which depends on nano-css. Even if I don't use useCss in the React Native application, I receive an error due to the nano-css dependency, where there is a check for a global variable that does not exist in a mobile environment.

A little about versions:

  • OS: macOs Sonoma v14.5
  • Browser (vendor and version):
  • React: v18.2.0
  • react-use: v17.5.0
  • Did this worked in the previous package version?

meluiz avatar Jul 04 '24 16:07 meluiz

+1

mrtawil avatar Jul 10 '24 11:07 mrtawil

+1

pranshuchittora avatar Jul 25 '24 04:07 pranshuchittora

+1

yinxulai avatar Jul 06 '25 03:07 yinxulai

I know that this is an old issue but importing the hooks you want to use via import useLatest from "react-use/lib/useLatest"; or import useLatest from "react-use/esm/useLatest"; allows you to get around the nano-css error that crops up on react-native projects. I've thought about potentially forking this library and having a react-native specific version to prevent this type of issue.

Bengejd avatar Sep 08 '25 17:09 Bengejd