Javascript 如何使用React中的start和end标记创建DOM组件?
在这里,我创建了一个组件Javascript 如何使用React中的start和end标记创建DOM组件?,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,在这里,我创建了一个组件SomeComponent const SomeComponent=()=>( 这里有一些文字 ) 我可以这样使用此组件: const SomeComponent = ({ children }) => ( <div className="some-class"> {children} </div> ) <SomeComponent>whatever content here
SomeComponent
const SomeComponent=()=>(
这里有一些文字
)
我可以这样使用此组件:
const SomeComponent = ({ children }) => (
<div className="some-class">
{children}
</div>
)
<SomeComponent>whatever content here</SomeComponent>
我想做同样的事情,但有一个开始和结束标记,如下所示:
这里有一些文字
我怎样才能做到这一点
非常感谢-奥利您可以作为儿童
属性访问“内容”
const SomeComponent = ({ children }) => (
<div className={"some-class"}>
{children}
</div>
)
constsomecomponent=({children})=>(
{儿童}
)
您可以通过子属性访问“内容”
const SomeComponent = ({ children }) => (
<div className={"some-class"}>
{children}
</div>
)
constsomecomponent=({children})=>(
{儿童}
)
您可以这样使用:
const SomeComponent = ({ children }) => (
<div className="some-class">
{children}
</div>
)
<SomeComponent>whatever content here</SomeComponent>
您可以这样使用:
const SomeComponent = ({ children }) => (
<div className="some-class">
{children}
</div>
)
<SomeComponent>whatever content here</SomeComponent>
你所需要做的就是寻找儿童
道具
const SomeComponent = ({ children }) => (
<div className="some-class">
{ children }
</div>
);
constsomecomponent=({children})=>(
{儿童}
);
子对象可以是文本、HTML或其他组件。您需要做的就是查找子对象
const SomeComponent = ({ children }) => (
<div className="some-class">
{ children }
</div>
);
constsomecomponent=({children})=>(
{儿童}
);
其中子项可以是文本、HTML或其他组件。className={“some class”}
可以简化为className=“some class”
甚至class=“some class”
@3limin4t0r我知道。我看到其他人这样做,所以我选择在这里发布。className={“some class”}
可以简化为className=“some class”
,甚至我知道class=“some class”
@3limin4t0r。我看到其他人这样做,所以我选择将其发布在这里。子对象可以是任何对象,而不仅仅是可渲染对象。根据使用情况,您可能会遇到麻烦。如果我将组件传递到何处并尝试渲染它,则会抛出一个错误。但是,如果我将其用作元素,它将正常工作,而普通对象或字符串则不会。例如,({children:Component})=>
需要一个组件(函数或类),然后可以使用例如{({value})=>{value}}
子对象
可以是任何对象,而不仅仅是可渲染对象。根据使用情况,您可能会遇到麻烦。如果我将组件传递到何处并尝试渲染它,则会抛出一个错误。但是,如果我将其用作元素,它将正常工作,而普通对象或字符串则不会。例如,({children:Component})=>
需要一个组件(函数或类),然后可以使用例如{({value})=>{value}}
调用该组件。