Answer the question
In order to leave comments, you need to log in
Error "Actions must be plain objects. Use custom middleware for async actions". How to decide?
There is a smart component:
function MethodWrapper(props) {
const API_METHOD = [
...
]
function submitHandler(event) {
event.preventDefault()
if (!props.method && !props.url) {
showAlert("Название поста не может быть пустым")
console.log(props)
}
}
return (
<form onSubmit={submitHandler}>
<Input />
<div className={style.methodWrapper}>
<Methods isActive={props.method} methodList={API_METHOD}/>
</div>
</form>
)
}
const mapDispatchToProps = {
showAlert, getURL, getMethod
}
const mapStateToProps = state => ({
alert : state.alert,
url : state.url,
method : state.method
})
export default connect(mapStateToProps, mapDispatchToProps)(MethodWrapper)
export function showAlert(text) {
return dispatch => {
dispatch({
type: SHOW_ALERT,
payload: text
})
}
}
import {HIDE_ALERT, SHOW_ALERT, REQUES_METHOD, GET_URL} from "./type";
export const initialState = {
alert : null,
url : null,
method : null
}
export const rootReducer = ( state = initialState, action) => {
switch (action.type) {
...
case SHOW_ALERT:
return {...state, alert : action.payload}
...
default : return state
}
}
Answer the question
In order to leave comments, you need to log in
The action must return an object
export const showAlert = text => ({
type: SHOW_ALERT,
payload: text
});
Learn how to properly connect to the Tutac store
Pay attention to mapDispatchToProps.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question