Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increased Prettier line-width for examples
Browse files Browse the repository at this point in the history
bvaughn committed Feb 7, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b8213fb commit 5997700
Showing 26 changed files with 87 additions and 231 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.examples
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"bracketSpacing": false,
"jsxBracketSameLine": true,
"parser": "flow",
"printWidth": 40,
"printWidth": 60,
"singleQuote": true,
"trailingComma": "es5"
}
9 changes: 2 additions & 7 deletions examples/16-3-release-blog-create-ref.js
Original file line number Diff line number Diff line change
@@ -3,13 +3,8 @@ class MyComponent extends React.Component {
divRef = React.createRef();

render() {
// highlight-range{4}
return (
<input
type="text"
ref={this.divRef}
/>
);
// highlight-next-line
return <input type="text" ref={this.divRef} />;
}

componentDidMount() {
5 changes: 1 addition & 4 deletions examples/components-and-props/composing-components.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,4 @@ function App() {
);
}

ReactDOM.render(
<App />,
document.getElementById('root')
);
ReactDOM.render(<App />, document.getElementById('root'));
14 changes: 4 additions & 10 deletions examples/components-and-props/extracting-components-continued.js
Original file line number Diff line number Diff line change
@@ -16,9 +16,7 @@ function UserInfo(props) {
return (
<div className="UserInfo">
<Avatar user={props.user} />
<div className="UserInfo-name">
{props.user.name}
</div>
<div className="UserInfo-name">{props.user.name}</div>
</div>
);
}
@@ -27,9 +25,7 @@ function Comment(props) {
return (
<div className="Comment">
<UserInfo user={props.author} />
<div className="Comment-text">
{props.text}
</div>
<div className="Comment-text">{props.text}</div>
<div className="Comment-date">
{formatDate(props.date)}
</div>
@@ -39,12 +35,10 @@ function Comment(props) {

const comment = {
date: new Date(),
text:
'I hope you enjoy learning React!',
text: 'I hope you enjoy learning React!',
author: {
name: 'Hello Kitty',
avatarUrl:
'http://placekitten.com/g/64/64',
avatarUrl: 'http://placekitten.com/g/64/64',
},
};
ReactDOM.render(
10 changes: 3 additions & 7 deletions examples/components-and-props/extracting-components.js
Original file line number Diff line number Diff line change
@@ -15,9 +15,7 @@ function Comment(props) {
{props.author.name}
</div>
</div>
<div className="Comment-text">
{props.text}
</div>
<div className="Comment-text">{props.text}</div>
<div className="Comment-date">
{formatDate(props.date)}
</div>
@@ -27,12 +25,10 @@ function Comment(props) {

const comment = {
date: new Date(),
text:
'I hope you enjoy learning React!',
text: 'I hope you enjoy learning React!',
author: {
name: 'Hello Kitty',
avatarUrl:
'http://placekitten.com/g/64/64',
avatarUrl: 'http://placekitten.com/g/64/64',
},
};
ReactDOM.render(
5 changes: 1 addition & 4 deletions examples/components-and-props/rendering-a-component.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,4 @@ function Welcome(props) {
}

const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);
ReactDOM.render(element, document.getElementById('root'));
4 changes: 1 addition & 3 deletions examples/es5-syntax-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const element = <h1>Hello, world!</h1>;
const container = document.getElementById(
'root'
);
const container = document.getElementById('root');
ReactDOM.render(element, container);
13 changes: 3 additions & 10 deletions examples/introducing-jsx.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
function formatName(user) {
return (
user.firstName + ' ' + user.lastName
);
return user.firstName + ' ' + user.lastName;
}

const user = {
firstName: 'Harper',
lastName: 'Perez',
};

const element = (
<h1>Hello, {formatName(user)}!</h1>
);
const element = <h1>Hello, {formatName(user)}!</h1>;

ReactDOM.render(
element,
document.getElementById('root')
);
ReactDOM.render(element, document.getElementById('root'));
61 changes: 16 additions & 45 deletions examples/reconciliation/index-used-as-key.js
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@ const ToDo = props => (
<input />
</td>
<td>
<label>
{props.createdAt.toTimeString()}
</label>
<label>{props.createdAt.toTimeString()}</label>
</td>
</tr>
);
@@ -31,35 +29,26 @@ class ToDoList extends React.Component {
}

sortByEarliest() {
const sortedList = this.state.list.sort(
(a, b) => {
return (
a.createdAt - b.createdAt
);
}
);
const sortedList = this.state.list.sort((a, b) => {
return a.createdAt - b.createdAt;
});
this.setState({
list: [...sortedList],
});
}

sortByLatest() {
const sortedList = this.state.list.sort(
(a, b) => {
return (
b.createdAt - a.createdAt
);
}
);
const sortedList = this.state.list.sort((a, b) => {
return b.createdAt - a.createdAt;
});
this.setState({
list: [...sortedList],
});
}

addToEnd() {
const date = new Date();
const nextId =
this.state.todoCounter + 1;
const nextId = this.state.todoCounter + 1;
const newList = [
...this.state.list,
{id: nextId, createdAt: date},
@@ -72,8 +61,7 @@ class ToDoList extends React.Component {

addToStart() {
const date = new Date();
const nextId =
this.state.todoCounter + 1;
const nextId = this.state.todoCounter + 1;
const newList = [
{id: nextId, createdAt: date},
...this.state.list,
@@ -89,28 +77,16 @@ class ToDoList extends React.Component {
<div>
<code>key=index</code>
<br />
<button
onClick={this.addToStart.bind(
this
)}>
<button onClick={this.addToStart.bind(this)}>
Add New to Start
</button>
<button
onClick={this.addToEnd.bind(
this
)}>
<button onClick={this.addToEnd.bind(this)}>
Add New to End
</button>
<button
onClick={this.sortByEarliest.bind(
this
)}>
<button onClick={this.sortByEarliest.bind(this)}>
Sort by Earliest
</button>
<button
onClick={this.sortByLatest.bind(
this
)}>
<button onClick={this.sortByLatest.bind(this)}>
Sort by Latest
</button>
<table>
@@ -119,14 +95,9 @@ class ToDoList extends React.Component {
<th />
<th>created at</th>
</tr>
{this.state.list.map(
(todo, index) => (
<ToDo
key={index}
{...todo}
/>
)
)}
{this.state.list.map((todo, index) => (
<ToDo key={index} {...todo} />
))}
</table>
</div>
);
61 changes: 16 additions & 45 deletions examples/reconciliation/no-index-used-as-key.js
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@ const ToDo = props => (
<input />
</td>
<td>
<label>
{props.createdAt.toTimeString()}
</label>
<label>{props.createdAt.toTimeString()}</label>
</td>
</tr>
);
@@ -31,35 +29,26 @@ class ToDoList extends React.Component {
}

sortByEarliest() {
const sortedList = this.state.list.sort(
(a, b) => {
return (
a.createdAt - b.createdAt
);
}
);
const sortedList = this.state.list.sort((a, b) => {
return a.createdAt - b.createdAt;
});
this.setState({
list: [...sortedList],
});
}

sortByLatest() {
const sortedList = this.state.list.sort(
(a, b) => {
return (
b.createdAt - a.createdAt
);
}
);
const sortedList = this.state.list.sort((a, b) => {
return b.createdAt - a.createdAt;
});
this.setState({
list: [...sortedList],
});
}

addToEnd() {
const date = new Date();
const nextId =
this.state.toDoCounter + 1;
const nextId = this.state.toDoCounter + 1;
const newList = [
...this.state.list,
{id: nextId, createdAt: date},
@@ -72,8 +61,7 @@ class ToDoList extends React.Component {

addToStart() {
const date = new Date();
const nextId =
this.state.toDoCounter + 1;
const nextId = this.state.toDoCounter + 1;
const newList = [
{id: nextId, createdAt: date},
...this.state.list,
@@ -89,28 +77,16 @@ class ToDoList extends React.Component {
<div>
<code>key=id</code>
<br />
<button
onClick={this.addToStart.bind(
this
)}>
<button onClick={this.addToStart.bind(this)}>
Add New to Start
</button>
<button
onClick={this.addToEnd.bind(
this
)}>
<button onClick={this.addToEnd.bind(this)}>
Add New to End
</button>
<button
onClick={this.sortByEarliest.bind(
this
)}>
<button onClick={this.sortByEarliest.bind(this)}>
Sort by Earliest
</button>
<button
onClick={this.sortByLatest.bind(
this
)}>
<button onClick={this.sortByLatest.bind(this)}>
Sort by Latest
</button>
<table>
@@ -119,14 +95,9 @@ class ToDoList extends React.Component {
<th />
<th>created at</th>
</tr>
{this.state.list.map(
(todo, index) => (
<ToDo
key={todo.id}
{...todo}
/>
)
)}
{this.state.list.map((todo, index) => (
<ToDo key={todo.id} {...todo} />
))}
</table>
</div>
);
5 changes: 1 addition & 4 deletions examples/rendering-elements/render-an-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
const element = <h1>Hello, world</h1>;
ReactDOM.render(
element,
document.getElementById('root')
);
ReactDOM.render(element, document.getElementById('root'));
12 changes: 3 additions & 9 deletions examples/rendering-elements/update-rendered-element.js
Original file line number Diff line number Diff line change
@@ -2,17 +2,11 @@ function tick() {
const element = (
<div>
<h1>Hello, world!</h1>
<h2>
It is{' '}
{new Date().toLocaleTimeString()}.
</h2>
<h2>It is {new Date().toLocaleTimeString()}.</h2>
</div>
);
// highlight-range{1-4}
ReactDOM.render(
element,
document.getElementById('root')
);
// highlight-next-line
ReactDOM.render(element, document.getElementById('root'));
}

setInterval(tick, 1000);
Loading

0 comments on commit 5997700

Please sign in to comment.