This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
export default class FormSample extends Component { | |
state = { | |
employer: "Gorrion" | |
}; | |
handleEmployerChange = e => { | |
this.setState({ employer: e.target.value }); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="field"> | |
<label class="label">Employer</label> | |
<div class="control"> | |
<input class="input" type="text" v-model="employer" /> | |
</div> | |
</div> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
export default class Counter extends Component { | |
state = { | |
title: "Counter", | |
counter: 0 | |
}; | |
incrementCounter = () => { | |
this.setState(prevState => ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<h1>{{ greeting }} world!</h1> | |
</template> | |
<script> | |
export default { | |
data () { | |
return { | |
greeting: 'Hello' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WorkerInfo extends React.Component { | |
state = { worker: null } | |
componentDidMount() { | |
// Simulate fetching data: | |
setTimeout(() => this.setState({ | |
worker: `Hi, I am ${this.props.name} and I am proud to work for ${this.props.employer}` | |
}), 2500); | |
} | |
render() { | |
return this.props.children(this.state.worker); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Worker = props => <p>{props.message}</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Loading = () => <p>Loading...</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Connect = ComposedComponent => | |
class extends React.Component { | |
state = { name: "" } | |
componentDidMount() { | |
//fetching data is a part of HOC | |
getAsync('https://imaginary-api.gorrion.io/name') | |
.then(({ name }) => { this.setState({ name: name }) }) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Greeting = ({ name, ...props }) => { | |
if (!name) { | |
return <div>Loading...</div> | |
} | |
return <div {...props}>Hi {name}!</div> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
class CommentListContainer extends React.Component { | |
state = { comments: [] } | |
componentDidMount() { | |
getAsync("https://imaginary-api.gorrion.io/my-comments") | |
.then(comments => this.setState({ comments })) | |
} | |
render() { | |
return <CommentList comments={this.state.comments} />; | |
} |