Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Thunk support #160

Closed
lostincomputer opened this issue Jan 20, 2020 · 3 comments
Closed

Thunk support #160

lostincomputer opened this issue Jan 20, 2020 · 3 comments

Comments

@lostincomputer
Copy link

lostincomputer commented Jan 20, 2020

Is Redux Thunk supported?

I configured my store to

import { createStore } from "redux";
import { rootReducer } from "./reducers";
import { composeWithDevTools } from "redux-devtools-extension";
import dynostore, { dynamicReducers } from "@redux-dynostore/core";
import thunk from "redux-thunk";
import { applyMiddleware } from "redux-subspace";

export const store = createStore(
rootReducer,
composeWithDevTools(dynostore(dynamicReducers()), applyMiddleware(thunk))
)

but my thunk doesn't get executed.

@mpeyper
Copy link
Contributor

mpeyper commented Jan 20, 2020

Yes, thunks are supported.

The store setup looks fine so I'll need to see the thunk and how you're dispatching it to help you out any further.

I'm on holidays at the moment, so my response times might be a bit slow.

@lostincomputer
Copy link
Author

I tested it again and it works now for some reason. I spent an hour trying to fix it yesterday and thought that it had something to do with your library. Sorry for wasting your time.

@mpeyper
Copy link
Contributor

mpeyper commented Jan 21, 2020

Ha, no worries.

I have to mention one thing though:

export const Spreadsheet = props => {
  const ConnectedSpreadsheet = dynamic(
    props.identifier,
    subspaced(),
    attachReducer(spreadsheetReducer)
  )(UnconnectedSpreadsheet);

  return <ConnectedSpreadsheet {...props} />;
};

There is an issue with this snippet. dynamic creates a higher-order component, which you shouldn't do as part of rendering (i.e. you should call it inside the Spreadsheet function component). See this article on the react docs for more details.

For basic use cases, you can us the createInstance function to change the identifier for multiple instances, but you do need to know what they identifiers are going to be.

I've seen cases where useMemo to dynamically change the identifier and only recreate the component when the identifier changes, and we've had discussions before about accepting identifier as a prop instead of having to statically assign them, but nothing has ever come of it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants