reactjs - Good practice to fetch detail api data in react-redux app -
whats best practice fetch details data in react app when dealing multiple master details view?
for example if have
- /rest/departments api returns list of departments
- /rest/departments/:departmentid/employees api return employees within department.
to fetch departments use:
componentdidmount() { this.props.dispatch(fetchdepartments()); }
but ill need logic fetch employees per department. great idea call employee action creator each department in department reducer logic?
dispatching employees actions in render method not idea me.
surely bad idea call employee action creator inside department reducer, reducers should pure functions; should in fetchdepartments action creator.
anyway, if need employees every department (not selected one), not ideal make many api calls: if possible, ask backend developers have endpoint returns array of departments and, each department, embedded array of employees, if numbers aren't big of course...
Comments
Post a Comment