Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
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.
Turn Your Knowledge into Earnings.
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
import { GET_REPORTS, GET_REPORT_BY_ID } from '../actions/types'; const initialState = { reports: [], report: {} }; export default function(state = initialState, action) { switch (action.type) { case GET_REPORTS: return { ...state, reports: action.payload }; case GET_REPORT_BY_ID: return { ...state, report: action.payload }; default: return state; } }
reportActions.js
import {GET_REPORTS, GET_REPORT_BY_ID} from './types'; import axios from 'axios'; export const getReports = () => async dispatch => { const res = await axios.get(`/api/report`); dispatch({ type: GET_REPORTS, payload: res.data }); }; export const 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
import React, {Component} from 'react'; import {getReportById} from '../../actions/reportActions'; import {connect} from 'react-redux'; class ReportById extends Component { constructor(props) { super(props); } componentDidMount = async () => { this.props.getReportById(this REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
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.
console.log
[object Object]
toString
If you need to print an object please try something like this:
console.log(JSON.stringify(this.props, null, 2));
You can skip the second and third arguments to stringify if unformatted JSON is okay for you.
Please note that this won't work if you are passing any circular object in props.
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.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.