(Yes)
(I am using npm v 3.10.10.)
(Execution Faild.)
node -v: v6.12.2npm -v: 3.10.10yarn --version (if you use Yarn):npm ls react-scripts (if you haven鈥檛 ejected): Then, specify:
(Write your steps here:)
create-react-app myapp1/*jshint esversion: 6 */
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import axios from 'axios';
//-------------Card Component ---------------------------------------
const Card = (props)=>
{
return (
<div>
<img width="75" src={props.Image}/>
<div className="info">
{props.Name}
</div>
<div>
{props.CompanyName}
</div>
</div>
)
}
//-------------Card List Component ---------------------------------------
const CardList =(props)=>{
return(
<div>
<p>Transform every element in CardsData array to Card component with typical properties of CardsData.OCard.</p>
<br/><br/>
{props.CardsData.map(oCard=> <Card {...oCard}/>)}
</div>
)
}
//-------------Form Component ---------------------------------------
class Form extends Component{
state = {txtChngedEvent : ""}
//every react event function receives an event argument which is wrapped
//to the native javascript event object.
handleSubmit = (event)=>
{
event.preventDefault();
axios.get(`https://api.github.com/users/${this.state.txtChngedEvent.value}`).then(
(resp)=>
{
this.setState(prevState=>({}),()=>{
console.log(this.prevState);
})
this.props.DoSubmit(resp.data);
}
);
}
handleChange = ()=>
{
if(this.state.txtChngedEvent.value.indexOf("dd") > -1)
{
this.state.txtChngedEvent.value = "";
}
console.log('Event : Form changed Text s', this.state.txtChngedEvent.value)
}
render()
{
return(
<form onSubmit={this.handleSubmit}>
<input type="text"
value={this.state.userName}
onChange = {
(event)=>
this.setState({txtChngedEvent : event.target},()=>{
this.handleChange();
})
}
placeholder="Github userName" required/>
<br/>
<button>Add Card </button>
</form>
)
}
}
//-------------Container Component ---------------------------------------
class AppCard extends Component{
state = {
data:
[
{
Image: "https://avatars0.githubusercontent.com/u/7?v:4",
Name: "Evan Phoenix",
CompanyName: "@hashicorp"
},
{
Image: "https://avatars1.githubusercontent.com/u/17?v:4",
Name: "Chris Van Pelt",
CompanyName: "crowdflower.com"
}
]
}
AddNewCard = (cardInfo)=>
{
console.log(cardInfo);
this.setState(prevState=>({CardList : prevState.CardList.concat(cardInfo)}))
};
render(){
return (
<div>
<Form DoSubmit={this.AddNewCard}/>
<CardList CardsData={this.state.data}/>
</div>
)
}
}
const AppsFactory = {
AppCard : AppCard
}
export default AppsFactory;
npm install axios --save, Built with no errors,but when executed , I got that this is undefined and a run time error appeared as followed :(I expect that the this.prevState had defined and had a value and I could modify it in the context of the this.setState funtion)
(Issue appeared, and couldn't move forward as followed :


)
(Paste the link to an example project and exact instructions to reproduce the issue.)
_This guy is kidding, right?_
Let me help although I'm a little bit mad about you creating a such issue in this repository.
Your issue is not related to the create-react-app. You did a few mistakes in your own code. You should grow up and try to find error on your own.
Please, take a look at the key is used in App component to store the cards and look at key you're using in AddNewCard method.
Also, you're managing React component state in a wrong way.
Consider reading and learning React documentation. It will help you in the future.
@miraage , appreciated your response, sorry for begin wrong in selecting proper location for the post.
I am a beginner, and try to gain experience, this sample is not mine, it was from a tutorial posted on a tutor web site which was totally wrong, and i changed it on my own.
Thanks for the advise, I appreciate if you review and give me your advise also.
this was my fix

with the following result:

@miraage
We don鈥檛 tolerate rudeness in this repository. Please avoid personal attacks and mockery in the future. If the question is off topic for a repository, there are perfectly polite ways to point that out without insulting the asker or questioning this intelligence.
@engmyahya
I鈥檓 sorry you got a rude response. It looks like you figured out the problem. Please don鈥檛 hesitate to ask questions in the future. We can鈥檛 promise to answer all of them, and issues that don鈥檛 directly relate to this repository will eventually get closed, but there鈥檚 nothing wrong with asking, and we try to help when we can!
@engmyahya @gaearon sorry if my response offended you.
We all make mistakes, let鈥檚 just make sure we stay friendly to beginners in the future. 馃檪
@gaearon thanks for your time and interference, @miraage I did not deem the incident to be issue, but it is friendly to know that you care and took time out to say sorry.
Most helpful comment
We all make mistakes, let鈥檚 just make sure we stay friendly to beginners in the future. 馃檪