Search code examples
reactjsreact-routercreate-react-app

Can react components be named with numbers?


I don't remember where, I saw a router using a 404 component like this

<Route component={404}/>

I have tried creating a component

const 404 = props => {
  return (<h1>This is a 404 page!</h1>)
}

And it doesn't even compile. I am using create-react-app and React Router.


Solution

  • No. JavaScript variables cannot begin with numbers but can contain numbers after the first character.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types

    You can name the error component something like Error404