redux-async-connect icon indicating copy to clipboard operation
redux-async-connect copied to clipboard

How to dispatch action client side only?

Open AndrewRayCode opened this issue 8 years ago • 3 comments

My use case: I need some actions to dispatch only on the client side. This includes on first page load. Right now I have something like:

@asyncConnect([{
    promise: ({ store: { dispatch, getState } }) => {
        if( !__SERVER__ ) {
            return dispatch( clientOnly() );
        }
    }
}]);

However this doesn't execute on the client side on first page load. It only executes if I navigate to the page at a later time.

See also https://github.com/erikras/react-redux-universal-hot-example/issues/971

AndrewRayCode avatar Feb 29 '16 22:02 AndrewRayCode

Similar issue here: https://github.com/Rezonans/redux-async-connect/issues/55

I think it's not clear how to declare deferred request with redux-async-connect. What are we missing?

andresgutgon avatar Mar 01 '16 18:03 andresgutgon

+1

kjanoudi avatar Mar 02 '16 00:03 kjanoudi

I was stuck with doing this as well, you can pass a filter prop to ReduxAsyncConnect. You can do something like:

ReactDOM.render(
  <Provider store={store}>
    <Router render={(props) => <ReduxAsyncConnect {...props} filter={item => !item.deferred} />} history={history}>
      {routes}
    </Router>
  </Provider>,
  dest
);

or whatever you'd like.

Discovered this after being referred to: https://github.com/erikras/react-redux-universal-hot-example/blob/615dfcd2562b8380e1d199b3d840d292358198dc/src/client.js#L39

babsonmatt avatar Mar 06 '16 07:03 babsonmatt