Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
My Reducer and Actions are working fine and I am logging my data through, but my logs in component where I am consuming my reducers state returns props as [object object], I am sure I am not logging it correctly or reading the json in right format. Here is the code:
import{GET_REPORTS, GET_REPORT_BY_ID} from './types';import axios from 'axios';exportconst getReports =()=>async dispatch =>{const res =await axios.get(`/api/report`);
dispatch({
type: GET_REPORTS,
payload: res.data
});};exportconst getReportById = id =>async dispatch =>{const res =await axios.get(`api/report/${id}`);
console.log(res.data);
dispatch({
type: GET_REPORT_BY_ID,
payload: res.data
});};
ReportById.jsx
importReact,{Component} from 'react';import{getReportById} from '../../actions/reportActions';import{connect} from 'react-redux';classReportById extends Component{constructor(props){
super(props);}
componentDidMount =async()=>{this.props.getReportById(this
Printing an Object with console.log will always print [object Object]. This happens because console.log will try to convert it's arguments to string by calling toString on them.
If you need to print an object please try something like this:
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that
you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice
sessions to improve your knowledge and scores.
manpreet
Best Answer
2 years ago
My Reducer and Actions are working fine and I am logging my data through, but my logs in component where I am consuming my reducers state returns props as [object object], I am sure I am not logging it correctly or reading the json in right format. Here is the code:
reportReducer.js
reportActions.js
ReportById.jsx