在我的核心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 |