Answer the question
In order to leave comments, you need to log in
How to get list of entities after page load?
After page loading I want to deduce the list of objects from base.
component
import React from 'react';
import { connect } from 'react-redux';
import { fetchEntities } from '../../actions/entityActions';
class EntityList extends React.Component {
componentWillMount() {
this.props.fetchEntities();
}
render() {
return (
<div className="col-md-8">
List Entities
</div>
);
}
}
const mapDispatchToProps = (dispatch) => {
return {
fetchEntities: () => {
dispatch(fetchEntities());
}
}
};
EntityList.propTypes = {
fetchEntities: React.PropTypes.func.isRequired
};
export default connect(null, mapDispatchToProps)(EntityList);
export function fetchEntities() {
const result = axios.get('/api/entities');
return {
type: FETCH_ENTITIES,
entities: result
}
}
import {FETCH_ENTITIES} from '../actions/types';
const initialState = [];
export default (state = initialState, action = {}) => {
switch (action.type) {
case FETCH_ENTITIES:
console.log(action.entities);
return state;
default:
return state;
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question