Closed
Description
Hey! (Warn: Rather new to Redux)
I have several forms on the same page that have inputs with suggests. So I thought I could possibly write abstract action creators for working with suggests:
import fetch from 'isomorphic-fetch';
export const FETCH_SUGGEST_DATA = 'FETCH_SUGGEST_DATA';
export const SET_SUGGEST_DATA = 'SET_SUGGEST_DATA';
export const fetchSuggestData = (url) => {
return function (dispatch) {
return fetch(url)
.then(response => response.json())
.then(json => dispatch(setSuggestData(json)))
}
};
export const setSuggestData = (json) => {
return {
type: SET_SUGGEST_DATA,
items: json.items
}
};
and pass suggest
reducer to different parts of the app reducer:
import { combineReducers } from 'redux';
import { suggest } from './form/suggest';
const app = combineReducers({
mainForm: combineReducers({
to: combineReducers({
suggest: suggest
})
}),
secondaryForm: combineReducers({
from: combineReducers({
suggest: suggest
})
}),
});
export default app;
If I dispatch a suggest action after onChange of any input triggers, I obviously get both suggests shown.
Is there any practice of specifying a part of the state for an action still keeping it abstract? Or maybe I should restructure the state somehow?
I've read this issue: #897 and those form examples were kinda close to the thing I'm trying to make. Still there is always a parent in these examples that must contain all of the inputs.