Browse Source

ternary operator use

master
Yutsuo 6 years ago
parent
commit
b46aad9d52
  1. 42
      02/src/App.js

42
02/src/App.js

@ -2,7 +2,8 @@ import React from 'react';
import './App.css'; import './App.css';
import Person from './Person/Person'; import Person from './Person/Person';
// // ## Functional code generated by creat-react-app ##
/* // ## Functional code generated by creat-react-app ##
// function App() { // function App() {
// return ( // return (
// <div className="App"> // <div className="App">
@ -16,8 +17,9 @@ import Person from './Person/Person';
// ); // );
// // return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`)); // // return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`));
// } // }
*/
// // ## Functional code created using ES6 (React Hooks) ## /* // ## Functional code created using ES6 (React Hooks) ##
// const App = props => { // const App = props => {
// const [charState, setCharState] = React.useState({ // const [charState, setCharState] = React.useState({
// character: [ // character: [
@ -62,6 +64,12 @@ import Person from './Person/Person';
// ); // );
// // return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`)); // // return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`));
// } // }
*/
/* // ## What's behind each JSX tag ##
// render() {
// return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`));
// }*/
// ## OOP code ## // ## OOP code ##
@ -72,7 +80,8 @@ class App extends React.Component {
{ name: 'char2', ilvl: 110 }, { name: 'char2', ilvl: 110 },
{ name: 'char3', ilvl: 78 } { name: 'char3', ilvl: 78 }
], ],
somethingElse: 'something something' somethingElse: 'something something',
showOrHide: false
} }
switchNameHandler = () => { switchNameHandler = () => {
@ -98,22 +107,38 @@ class App extends React.Component {
}) })
} }
showOrHide = () => {
const doesShow = this.state.showOrHide
this.setState({showOrHide: !doesShow})
}
render() { render() {
const style = { const style = {
backgroundColor: 'white', backgroundColor: 'white',
font: 'inherit', font: 'inherit',
border: '1px solid blue', border: '1px solid blue',
padding: '8px', padding: '8px',
margin: '10px',
cursor: 'pointer' cursor: 'pointer'
}; };
return ( return (
<div className="App"> <div className='App'>
<h1>Hi, I'm a React App, I'm cute.</h1> <h1>Hi, I'm a React App, I'm cute.</h1>
<p>Created using OOP code</p> <p>Created using OOP code</p>
<button <button
style={style} style={style}
onClick={() => this.switchNameHandler()}>Switch Char</button> onClick={() => this.switchNameHandler()}>
Switch Char
</button>
<button
style={style}
onClick={this.showOrHide} >
{this.state.showOrHide ? 'HIDE IT' : 'SHOW IT'}
</button>
{this.state.showOrHide
?
<div>
<Person <Person
name={this.state.character[0].name} name={this.state.character[0].name}
ilvl={this.state.character[0].ilvl} ilvl={this.state.character[0].ilvl}
@ -128,13 +153,10 @@ class App extends React.Component {
name={this.state.character[2].name} name={this.state.character[2].name}
ilvl={this.state.character[2].ilvl} ilvl={this.state.character[2].ilvl}
/> />
{/* <br /> </div> : null
<Person name="Yutsuo" ilvl="320">Main Character</Person> }
<Person name="Schwarzgeist" ilvl="200" />
<Person name="Murom" ilvl="78" /> */}
</div> </div>
); );
// return React.createElement('div', {className: 'App'}, React.createElement('h1', null, `Oh Hay I'm a React App!!!`));
} }
} }

Loading…
Cancel
Save