Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting index.js and app.js code #6

Open
jema28 opened this issue Apr 28, 2019 · 0 comments
Open

Splitting index.js and app.js code #6

jema28 opened this issue Apr 28, 2019 · 0 comments

Comments

@jema28
Copy link

jema28 commented Apr 28, 2019

It's good practice to separate the app code from index.js so the index.js only includes the react render and App import 🙂

import React from 'react';
import ReactDOM from 'react-dom';
import App from '..'

ReactDOM.render(<App />, document.getElementById('root'));

Reference:

import React from 'react';
import ReactDOM from 'react-dom';
import Input from './components/input';
import PortfolioCard from './components/card';
import "./style.css";
import { getData, API_BASE } from "./tools/getData";
class App extends React.Component {
state = {
userOne:"",
userTwo:"",
userOneData:'',
userTwoData:'',
}
// componentDidUpdate(){
// alert(this.state.userOne + this.state.userTwo);
// }
onclickHandler = () => {
const username1 = this.state.userOne;
const username2 = this.state.userTwo;
// const url = `${API_BASE}/users/tamernasser`;
const url1 = `${API_BASE}/users/${username1}`;
const url2 = `${API_BASE}/users/${username2}`;
getData(url1).then(d =>{
console.log(d);
this.setState( {userOneData:d} );
});
getData(url2).then(d =>{
console.log(d);
this.setState( {userTwoData:d} );
});
}
render(){
return(<div>
<div className="inputs-container">
<Input updateUser={(value) => this.setState({ userOne: value})}/>
<button onClick={this.onclickHandler} />
<Input updateUser={(value) => this.setState({ userTwo: value})} />
</div>
<div className="cards-container">
<PortfolioCard userdata={this.state.userOneData} />
<img />
<PortfolioCard userdata={this.state.userTwoData}/>
</div>
</div>
)}}
ReactDOM.render(<App/>, document.getElementById('ter'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant