Coggle requires JavaScript to display documents.
<Greet name="Bruce" heroName="Batman"/>
<Greet name="Bruce" heroName="Batman"> <p>This is children props</p> </Greet>
changeMessage() { this.setState({ message: "Thank you for subscribing" }) }
increment() { this.setState( {count: this.sate.count +1 }, () => { console.log('Callback value' , this.state.count) } ) console.log(this.state.count) }
increment() { this.state((prevState, props) => ({ count: prevState.count + props.argument })) console.log(this.state.count) }
const Greet = props => { const **{name , heroName} = props** return ( <div> Hello {name} a.k.a. {heroName} </div> ) }
const Greet = **{name, heroName}** => { return ( <div> Hello {name} a.k.a. {heroName} </div> ) }
<button onClick={clickHandler}>Click</button>
<button onClick={this.clickHandler}>Click Me</button>
<button onClick={this.clickHandler.bind(this)}>Click</button>
<button onClick={() => this.clickHandler()}>Click</button>
constructor(props) { super(props); this.state = { message: "Hello", }; this.clickHandler = this.clickHandler.bind(this); }
<button onClick={this.clickHandler}>Click</button>
differently (WORKD GOOD, BUT IS NEW FEATURE) clickHandler = () => { this.setState({ message: "Goodbye!!", }); };
<button onClick={() => props.greetHandler("child")}>Greet Parent</button>
constructor(props) { super(props); this.state = { isLoggedIn: false, };}
render() { if (this.state.isLoggedIn) { return <div>Welcome Vishwas</div>; } else { return <div>Welcome Guest</div>; }
render() { let message; if (this.state.isLoggedIn) { message = <div>Welcome Vishwas</div>; } else { message = <div>Welcome Guest</div>; } return <div>{message}</div>; }
render() { return this.state.isLoggedIn ? ( <div>Welcome Vishwas</div>
return render() { this.state.isLoggedIn && <div>Welcome Vishvas</div> }
function NameList() { const names = ["Bruce", "Clark", "Diana"]; return ( <div> {names.map((name) => ( <h2>{name}</h2> ))} </div> ); }
function NameList() { const names = ["Bruce", "Clark", "Diana"]; const nameList = names.map((name) => <h2>{name}</h2>); return <div>{nameList}</div>; }
<Person key={person.id} person={person} />
const nameList = names.map((name, index) => ( <h2 key={index}> {index} {name} </h2>)); return <div>{nameList}</div>; }