/    Sign up×
Community /Pin to ProfileBookmark

React Promise get returned data inside of JSX code from .then()?

Hi! I simply have a Comment component and I can get the data that I am looking for using a Promise inside of .then() but if I want to display the data in an JSX element down at the render/return things, I do not know how to do.

I tried putting the return statement inside of the .then() but I guess that is a very incorrect approach. I just simply want to display the data of the comment in a div element so that the user can see that.

So instead of: `text={this.props.text}` it shold be possible to do: `text={this.comment}` or something
` render() {
FirebaseFunc.getComment(this.props.userId, this.props.storyId, ‘[id of comment here]’).then((comment) => {
console.log(‘COMMENT PROMISE’);
console.log(comment); // **<– I want to get this data into the “real comment”**
});

return (
<Comment.Group>
<Comment>
<Comment.Content>
<Comment.Author as=’a’>Du</Comment.Author>
<Comment.Metadata>
<div>12:00 Idag</div>
</Comment.Metadata>
<Comment.Text >
<CommentEdit text={this.props.text} />
</Comment.Text>
<Comment.Actions>
<Comment.Action>Kommentera</Comment.Action>
<Comment.Action onClick={() => CommentAction.edit(this.props.text)}>Redigera</Comment.Action>
</Comment.Actions>
</Comment.Content>
</Comment>
</Comment.Group>

)
}`

[upl-image-preview url=https://www.webdeveloper.com/assets/files/2020-03-18/1584559361-271639-comment.jpeg]

to post a comment
HTMLJavaScript

0Be the first to comment 😎

×

Success!

Help @DecoratorFawn82 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.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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