码迷,mamicode.com
首页 > 其他好文 > 详细

[Recompose] Lock Props using Recompose -- withProps

时间:2017-05-15 09:52:31      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:use   obj   get   blog   pos   products   tin   document   ntb   

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

标签:use   obj   get   blog   pos   products   tin   document   ntb   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!