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

'Invariant violation' error when used with Route.render and hooks

Open dogancana opened this issue 7 years ago • 1 comments

Hi, React hooks throws 'Invariant violation' error when used with Route.render method. I was trying to implement small custom hooks in my existing application and realised

render={Foo} throws exception render={() => } works fine component={Foo} works fine

I'm not sure if this is a bug or expected behaviour. But if it's not a bug, it might be good idea to create a rule in eslint react hooks.

Versions: "react": "16.7.0-alpha.0 - next", "react-dom": "16.7.0-alpha.0 - next", "react-router-dom": "4.4.0-beta.6", "react-scripts": "2.1.1"

Testcase modified from a blogpost: https://codesandbox.io/s/40pzmw4w8w

See App.js AppWithRouter component

dogancana avatar Jan 11 '19 14:01 dogancana

render={Foo} isn't correct. It should be a plain function, not a component.

timdorr avatar Jan 11 '19 15:01 timdorr