如何将属性传递给无状态/功能组件?

时间:2017-05-11 15:26:10

标签: javascript reactjs

在我的核心index.js我正在渲染这样的组件:

<TestBundle lang={lang} />

我想要获取该组件中的lang属性。

为什么在<TestBundle />中呈现变量时,变量是未定义的?

const TestBundle = (lang) => (
  <section className='relative-container'>
    <div className='row'>
        {lang}
    </div>
  </section>
)

export default TestBundle

=============================================== ===========

所以这里有一个修改

const TestBundle = (props) => {
  const lang = props.lang
  // ...

//不同的例子

const TestBundle = (props) => {
    const lang = props.lang

      <section className='relative-container'>
        <div className='row'>
            {lang}
        </div>
      </section>
}

export default TestBundle

- 但这会出现错误

./src/components/Services/TestBundle.js
Module build failed: SyntaxError: D:/wamp/www/project/react/src/components/Services/TestBundle.js: Unexpected token (5:2)

  3 | 
  4 | const TestBundle= (props) => {
> 5 |   const lang = props.lang
    |   ^
  6 |   
  7 |   <section className='relative-container'>
  8 |     

0 个答案:

没有答案