zoukankan      html  css  js  c++  java
  • [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.

  • 相关阅读:
    学习网站
    支付宝调用错误:Call to undefined function openssl_sign()
    打包APP
    PHP 转义
    tp5学习
    js函数
    php学习随笔--定时触发
    day07
    60.函数应用:学生管理系统
    59.列表推导式
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6854734.html
Copyright © 2011-2022 走看看