jsx
- 傳播屬性 spread attribute
將單獨定義的屬性對象變量作為組件的props
const myProps = {
a: 1,
b: 2,
}
<myComponent {...myProps} />
- jsx中寫表達式和變量
jsx中的表達式要用{}括起來。
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
{isLoggedIn ? (
<LogoutButton onClick={this.handleLogoutClick} />
) : (
<LoginButton onClick={this.handleLoginClick} />
)}
</div>
);
}
renderFullName () {
return `${this.props.firstName} ${this.props.lastName}`;
}
ES6 箭頭函數
非方法函數
純函數
redux到底是啥
react router
每一個路由(Route)中聲明的組件(比如 SignIn)在渲染之前都會被傳入一些 props,具體是在源碼中的 RoutingContext.js 中完成,主要包括:
- history 對象,它提供了很多有用的方法可以在路由系統(tǒng)中使用,比如剛剛用到的 history.replaceState,用于替換當前的 URL,并且會將被替換的 URL 在瀏覽器歷史中刪除。函數的第一個參數是 state 對象,第二個是路徑;
- location 對象,它可以簡單的認為是 URL 的對象形式表示,這里要提的是 location.state,這里 state 的含義與 HTML5 history.pushState API 中的 state 對象一樣。每個 URL 都會對應一個 state 對象,你可以在對象里存儲數據,但這個數據卻不會出現(xiàn)在 URL 中。實際上,數據被存在了 sessionStorage 中;