/    Sign up×
Community /Pin to ProfileBookmark

Objects are not valid as react components

Hi,
In the following react component, I get “”Objects are not valid as react components”” error in the h1 tag of Welcome component, I looked up this error but couldn’t figure out how to solve it.

Thank you for your recommandations.

import React, {useState, useEffect} from ‘react’;
import ‘./App.css’;
import axios from ‘axios’;

function Welcome(props) {
return <h1>{props.name}</h1>;
}

function Summary() {

const [sum,setSum]=useState(

);

useEffect(() => {
const apiUrl = `/topic`;
axios.get(apiUrl)
.then((summary) => {
setSum(summary);
});
}, [setSum]);




return (
<div>
<Welcome name={sum} />
</div>
);
}

export default Summary;

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@bwclovisJul 01.2020 — Looks like your passing in the entire response which is more than likely an object. Try logging out the response, it will give you a better idea of what to pass ( probably looks like sum.name).
Copy linkTweet thisAlerts:
@ososauthorJul 01.2020 — The problem is related to the h1 tag but I cannot understand why. How can I return {props.name} in another way.

The tutorial I followed is the following: https://fr.reactjs.org/docs/components-and-props.html
Copy linkTweet thisAlerts:
@bwclovisJul 01.2020 — Well... what does get return (you can console log inside the then).
×

Success!

Help @osos spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...