在react官网里发现了这个东西,不知道以后能不呢个用的到,先记一下。
Children Props
这个就很常见了,在使用的时候嵌套组件进去,在Sidebar 或是 Dialog里比较常用到。
function OtherOne(props){return<div style={{background:"orange"}}><span>other one</span>{props.children}</div>}class Zuhe extends React.Component{constructor(props){super(props);}render(){return<div><OtherOne><h1>组合1</h1></OtherOne></div>}}
Other Props
我比较愿意称它们为奇怪的props,先看代码
class Zuhe extends React.Component{constructor(props){super(props);}render(){return<div><OtherOne><h1>组合1</h1></OtherOne><OtherTwoleft={<Left/>}right={<Right/>}left1 = {<div>left</div>}right2 = {<div>right</div>}/></div>}}function OtherTwo (props){console.log('other two props',props)return <div style={{border:'1px solid #eee'}}><span> other two</span><div style={{width:200,height:200}}><div style={{float:"left"}}>{props.left1}</div><div style={{float:"left"}}>{props.left}</div><div style={{float:"right"}}>{props.right2}</div><div style={{float:"right"}}>{props.right}</div></div></div>}function Left (props){return <div style={{border:'1px solid red'}}>i am left</div>}function Right (props){return <div style={{border:'1px solid green'}}>i am right</div>}
我一开始以为只能传 left,right属性,没想到它完全是自定义的。
可以理解为,用props传过去一个组件 😺!!是不是很牛
但是可以这么理解,
好像也挺对的。
我们可以看到此时的props,确实传来的是对象:
拓展
在上面的内容中,还可以简单窥探下react 元素对象的结构,就是把一些Dom转换成了啥样对像给react解析。

一级一级的往下写,文案也算。我以前学过这些的,生气,全忘了,有时间还要再整理出来。
