在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ react的案例疑惑

react的案例疑惑

看了下這個(gè)大神寫的react案例
我之前用的是vue,大多數(shù)react還是能看明白,但是不知道
這里的這個(gè)頁(yè)面用意是什么,
特別是這行,這種寫法讓人感到好懵,這是什么個(gè)意思?

render() {
            return <this.props.seting.component {...this.props} state={this.props.state.toJS()}/>;
        }

求大神解惑下,

回答
編輯回答
故人嘆

其實(shí)就是this.props.setting.component是一個(gè)由父組件傳下來(lái)的組件

2018年1月12日 03:25
編輯回答
柚稚
//這是一個(gè)函數(shù)
function f(a, b){
  return a + b;
}

f(1, 2) // 3

// 這是一個(gè)接受函數(shù)的函數(shù):
function f(fn, a, b){
  return fn(a, b);
}

var add = function (a, b) { return a + b;}
f(add, 2, 3); // 5

組件是一回事:

//這是一個(gè)組件
class A extends React.Component {
  render() {
    return <div>{this.props.hello}</div>
  }
}

// <A hello="hi"></A>  
// render =>
// <div>hi</div>

//寫一個(gè)接受組件為 props 的組件
class B extends React.Component {
  render () {
    var c = this.props.component;
    // 和 vue 不同的是,組件并不需要注冊(cè),組件名只要是當(dāng)前作用域下可用的變量就行
    // 所以直接 <this.props.component></this.props.component> 也是可以的
    // 因?yàn)?jsx 翻譯后就是 createElement(component, props, children)
    return <c {...this.props}></c>
  }
}

// <B component={A} hello="what's up!"></B>
// render =>
// <div>what's up/div>

其實(shí)這個(gè)例子用高階組件更合適的。

2017年7月1日 05:55