[Recompose] Lock Props using Recompose -- withProps

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Recompose] Lock Props using Recompose -- withProps相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

[Recompose] Transform Props using Recompose --mapProps

React Recompose 在 Props 上导致 Typescript 错误

[Recompose] Stream Props to React Children with RxJS

[Recompose] Make Reusable React Props Streams with Lenses

[Recompose] Create Stream Behaviors to Push Props in React Components with mapPropsStream

如何在 reactjs 中使用 recompose 清理表单?