javascript - React calls stateless components React is not defined
伊谢尔伦
伊谢尔伦 2017-06-14 10:54:33
0
2
880

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 />
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
洪涛

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.

女神的闺蜜爱上我

<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...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template