首页 > 其他 > 详细

[Recompose] Lock Props using Recompose -- withProps

时间:2017-05-15 09:25:29      阅读:273      评论:0      收藏:0      [点我收藏+]

Learn how to use the ‘withProps’ higher order component to pre-fill a prop, unable to be overridden.

 

const { Component } = React;
const { withProps } = Recompose;

// with function as arguement
const HomeLink = withProps(({ query }) => ({ href: #/?query= + query }))(a);
// take object as arguement
const ProductsLink = withProps({ href: #/products })(a);
const CheckoutLink = withProps({ href: #/checkout })(a);

const App = () =>
  <div className="App">
    <header>
      <HomeLink query="logo">Logo</HomeLink>
    </header>
    <nav>
      <HomeLink>Home</HomeLink>
      <ProductsLink>Products</ProductsLink>
      <CheckoutLink>Checkout</CheckoutLink>
    </nav>
  </div>;

ReactDOM.render(
  <App />,
  document.getElementById(main)
);

 

withProps, take string as arguement for creating a new DOM element.

[Recompose] Lock Props using Recompose -- withProps

原文:http://www.cnblogs.com/Answer1215/p/6854734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!