question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using signals package with react router results in a wierd jsx error

See original GitHub issue

I tried using @preact/signals-react in a project with react-router 6 but I got that error which doesn’t make any sense to me, the error is complaining about react-router but originates from @preact/signals-react and only happens when I import/use anything from @preact/signals-react

image

here is a link https://stackblitz.com/edit/react-router-starter-gfxkdm?file=components%2FHome.js to reproduce the error, try commenting out the signal import/usage in Home.js and everything will work fine

I think it could be related to the patches to JSX factories, which breaks the react-router check for the <Route/> element type somehow, if I used it with the routing config approach from react-router 6.4 it works fine

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
developitcommented, Nov 22, 2022

@lennerd the fix may be to go back to injecting updaters into components via react internals rather than wrapping all components. I’ve been using and testing a local version of that approach this week, and it’s working in dev and prod builds using React Router 6.4.

1reaction
salamaashoushcommented, Oct 26, 2022

couldn’t find a workaround for this error so I had to use the @preact/signals-core package with this custom hook

export function useSignalValue<T>(signal: Signal<T>) {
  const [value, setValue] = useState<T>(() => signal.peek());
  useEffect(() => signal.subscribe(setValue), [signal]);
  return value;
}

that allowed me to update the signals from anywhere and then where I use that hook react will rerender because of the local state update

it is not the best/optimal solution but hopefully, this issue with react-router could be fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · preactjs/signals - GitHub
Contribute to preactjs/signals development by creating an account on GitHub. ... Using signals package with react router results in a wierd jsx error...
Read more >
Error: Router cannot be used as a jsx component
reactjs - Error: Router cannot be used as a jsx component - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing ......
Read more >
React Router DOM: How to handle routing in web apps
React Router DOM contains the DOM bindings for React Router. Learn about its essential components and how to build routes with parameters.
Read more >
Documentation - SolidJS · Reactive Javascript Library
A declarative, efficient and flexible JavaScript library for building user interfaces.
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
In this post you'll learn how to fix the 'cannot GET /URL' error with React Router. Along the way, you'll also learn how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found