score:3
you can 'wrap' those functions in 'click handler'.
//call it on button click
handleclick = () => {
if (validate()) {
//call save function
save()
}
}
validate = () => {
//do something
//check validness and then
if (valid) return true
}
score:5
there are many ways to do what you'd like. however, as a general rule, don't store anything in redux that can be derived. isvalid
can be derived by running your validation on your field(s). moreover, i don't think that intermediate state like form field values that are changing belong in redux. i'd store them in react state until they're considered valid and submitted.
with that out of the way, as spooner mentioned in a comment, you can call a sync action within a thunk. or you can access state within the thunk.
option #1
// action creator
export default function dosomething(isvalid) {
return (dispatch) => {
dispatch(setvalid(isvalid));
if (isvalid) {
return fetch() //... dispatch on success or failure
}
};
}
option #2
// component
dispatch(setvalid(isvalid));
dispatch(dosomething());
// action creator
export default function dosomething() {
return (dispatch, getstate) => {
const isvalid = getstate().isvalid;
if (isvalid) {
return fetch() //... dispatch on success or failure
}
};
}
Source: stackoverflow.com
Related Query
- Redux call action after other action if condition
- How to call redux action after success of another action?
- react redux async action call next function after finishing the function
- How to call callback function after dispatch action Redux
- Redux state is nested after call an action
- How to listen for specific property changes in Redux store after an action is dispatched
- React router redirect after action redux
- React Redux dispatch action after another action
- Call function after dispatch from redux has finished
- Can I send an AJAX call in React and Redux without action creators and reducers?
- Redux ToolKit: is it possible to dispatch other actions from the same slice in one action created by createAsyncThunk
- Redux - how to call an action creator from inside another action creator?
- how and when to call a react component methods after state change from redux
- Redux - how to call an action and wait until it is resolved
- Call a Redux Action inside a useEffect
- Dispatching new action after global state changes in react redux
- How do I test a Redux action creator that only dispatches other actions
- Dispatch Redux action after React Apollo query returns
- How to use the updated value in redux store immediately after the action is dispatched in react js functional components
- React Redux with redux-observable use the router to navigate to a different page after async action complete
- Call redux action within redux-saga inside websocket callback (stomp + sockjs)
- How action and reducers are connected with each other in react redux
- Clear form after redux action succeeds
- How to call redux-saga action continuously after every 60 seconds
- React Redux setState after action is dispatched
- Run Redux action only when two other actions were triggered
- Redux sending two dispatch after each other then the first dispatch get lost
- Is there an accessible way of telling that some part of UI can redirect to other page if some asynchronous condition is resolved after clicking link?
- Handling Redux Saga result in view from which action call originates
- How to update a field value after action dispatched with redux
More Query from same tag
- React Input Type not editable
- In what cases would ignoring the spread operator in useReducer cause bugs?
- How can i use localStorage on my React app?
- Exporting scene in GLTF format from react-three-fiber
- TypeError: Cannot read property 'comments' of undefined in React
- React-Error: Too many re-renders. React limits the number of renders to prevent an infinite loop
- React conditionally set navigation
- How to make a layout with Styled Components?
- React search and filter methods issue
- What is the correct fetch body in React with FileReader
- Bad ComponentDidMount function ate into my 95000 daily call - ReactJS
- How to get and output a value from the select tag
- Store Credentials in Redux store is a good practice?
- Conditional alternating Parent tags in jsx
- Font Awesome icon in React
- React-Bootstrap Horizontal Form not working
- How to show snackbar on request success, failure in Redux?
- Instead of "for" in label what can i use?
- React Hooks State update one step behind. For this reason my changes are not working correctly
- Reactjs closure issue with event handlers
- Async variable appearing empty in conditional logic, yet it is present in console logs
- How do i open DrawerNavigator upon clicking Bottom Tab Navigator in React-Navigation?
- Fill model value from an object.
- How can I fix "Change tab after reloading page ."
- RelayObservable: Unhandled Error TypeError: Cannot read property 'subscribe' of undefined in React and Relay
- reactjs/react-router-dom: Browserrouter routing question
- How can I remove an attribute from a React component's state object
- Set <select> default value with redux-form in React
- MBDReact: How do I make a <datatable> row clickable?
- Ref issue using react-hook-form