ZeviLiao
8/26/2018 - 4:53 AM

HOCs

Very simple HOCs


const mapProps = propsMapper => WrappedComponetnt => props => () => {
  return <WrappedComponetnt {...propsMapper(props)} />
}

const Post = ({ title, content }) => (
  <div>
    <h1>{title}</h1>
    <p>{content}</p>
  </div>
)

const props = {
  aa: "aa",
  bb: "bbb"
}

const propsMapper = ({ aa: title, bb: content }) => ({
  title,
  content
})

const PostWithData = mapProps(propsMapper)(Post)(props)

ReactDOM.render(<PostWithData />, document.getElementById("app"))

//https://www.youtube.com/watch?v=zD_judE-bXk