Answer the question
In order to leave comments, you need to log in
Why does Actions must be plain objects fall out. Use custom middleware for async actions if the middle is connected?
store.tsx
import {
createStore as createReduxStore,
applyMiddleware,
} from 'redux'
import thunk from 'redux-thunk'
import {composeWithDevTools} from 'redux-devtools-extension'
import rootReducer from './reducers'
import {configJsonSchema} from '../json-schemas'
import validateConfig from '../app/validate-config'
import {Config} from '../types'
const parseConfig = (jsonConfig: Config): any => {
return {
config: jsonConfig,
}
}
export default function createStore(config: Config): any {
const initialState = parseConfig(config)
const checkSchemaResult = validateConfig(
config,
configJsonSchema,
)
if (checkSchemaResult === true) {
return createReduxStore(
rootReducer,
initialState,
composeWithDevTools(applyMiddleware(thunk)),
)
} else {
throw checkSchemaResult
}
}
import 'babel-polyfill'
import * as React from 'react'
import {render} from 'react-dom'
import {Provider} from 'react-redux'
import App from './ui/app'
import createStore from './store/store'
import {Config} from './types'
export default function initFeature(options: {
rootEl: HTMLElement
config: Config
}): void {
render(<Component config={options.config} />, options.rootEl)
}
export const Component: React.SFC<{config: Config}> = (
props: any,
): any => {
return (
<Provider store={createStore(props.config)}>
<App />
</Provider>
)
}
private handleSetCountryInStore = (
e: React.FormEvent<HTMLButtonElement>
): any => {
const countryId: number = Number(e.currentTarget.dataset.id);
this.props.selectCountry(this.props.config.countries[countryId]);
};
const selectCountry = (country: any): any => {
console.log(country);
};
Actions must be plain objects. Use custom middleware for async actions
Answer the question
In order to leave comments, you need to log in
const selectCountry = (country: any): any => {
console.log(country);
return {
type: 'MY_TEST_ACTION',
}
};
const selectCountry = (country: any): any => ({ // добавилось (
type: 'MY_TEST_ACTION',
}); // добавилось )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question