Amiramix Amiramix - 2 months ago 19
React JSX Question

Is paramemterless connect valid?

I sometimes see the following in our code:

@connect(() => ({}))
export default class SomeClass extends Componet {
(...)
};


I would understand if
connect
was taking any arguments, e.g.
state
, but does it have any purpose when it's parameter-less?

Answer

It Injects to component just dispatch function. You can access dispatch in component through this.props.dispatch.

Api docs github.com/reactjs/react-redux/blob/master/docs/api.md#examp‌​les

if you don't map any slice of state to props, you should use connect(), otherwise it doesnt make any sense. Connected component will be notified , and it will invoke checking shalow equality of new stateProps and previous stateProps.

Comments