Answer the question
In order to leave comments, you need to log in
Why are all the properties I pass to the component displayed at once?
Can you tell me how to properly pass properties to the 'Description' component? I have an array 'name', I use 'map' to get only 1 name from it, but I get all the names at once.
I do the same with 'Main', but everything is displayed correctly there.
Please help me fix the error.
It should look like this:
1 --> this page is 1. name is kate
2 --> this page is 2. name is jhnon
3 --> this page is 3. name is michael
Answer the question
In order to leave comments, you need to log in
https://codesandbox.io/s/card-routing-forqna-js-re...
In this sandbox, I decided everything, you just need to pass in the Description not an id (as you had) but a whole array of names, and then, depending on the card id (params.id), substitute the name from the array at the index of the clicked card:
I do minus 1 because everything in the array is counted from zero, and when I click on the first card, for example, it gives me the number 1, which would not be correct when displayed.
PS
It's better not to do it like you did in this.state:<p>name is {this.props.names[params.id - 1]}</p>
this.state = {
card: [1, 2, 3],
names: ["kate", "jhon", "michael"]
};
this.state = {
cards: [
{ card_id: 1, user_name: "kate" },
// и так далее
]
};
this.state = {
users: [
{ user_id: 1, user_name: "kate", /* и прочая информация */ }
],
cards: [
{ card_id: 1, creator_id: 1 /* эту карточку создала kate под айдишником 1 */ }
// например создатель карточки, и после по этому id ты можешь достать инфу о этом создателе
]
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question