odoku / React-Redux-Sample

0 stars 0 forks source link

HOC の形 #8

Open suttang opened 6 years ago

suttang commented 6 years ago

redux の connect も HOC なのでまとめると良さそう

// Component
// ==================================================================
const BaseComponent: React.SFC<Props> = () => (
  <div>
    <h1>Hello!!!!</h1>
    <Link to='/login'>Login</Link>
  </div>
)

const connector = connect(() => ({}), () => ({}))
const enhancer: HOC<Props, Props> = compose(
  connector,
  setDisplayName('Home'),
  pure
)

// Redux connect
// ==================================================================
export default enhancer(BaseComponent)
suttang commented 6 years ago
const enhancer: HOC<Props, Props> = compose(
  connect(mapStateToProps, mapDispatchToProps),
  setDisplayName('Home'),
  pure
)

のほうがシンプルか。