Home  >  Q&A  >  body text

javascript - React calls stateless components React is not defined

I created a stateless component and called it. The result was an error: React is not defined. As a result, if I added import React from 'react' before defining the stateless component, the error would not be reported.

import React from 'react'
export default props=><p>123123123</p>


import HasNoState from './HasNoState'

<HasNoState />
伊谢尔伦伊谢尔伦2708 days ago826

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-06-14 10:56:33

    You thought you didn’t use React.

    But when jsx is parsed into js, ​​React needs to be called, so if you don’t introduce React here, you will naturally get an error.

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-14 10:56:33

    <HasNoState /> This way of instantiating components is a syntactic sugar encapsulated by react. To use it, react must be introduced in the scope.
    React Must Be in Scope...
    I suggest you go to the official documentation to take a closer look. Look, the part about jsx
    https://facebook.github.io/re...

    reply
    0
  • Cancelreply