Skip to content

Commit

Permalink
Make CodePen links more prominent and consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jun 23, 2018
1 parent 3d38ca4 commit db66436
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 63 deletions.
8 changes: 4 additions & 4 deletions content/docs/components-and-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ReactDOM.render(
);
```

[](codepen://components-and-props/rendering-a-component).
[](codepen://components-and-props/rendering-a-component)

Let's recap what happens in this example:

Expand Down Expand Up @@ -118,7 +118,7 @@ ReactDOM.render(
);
```

[](codepen://components-and-props/composing-components).
[](codepen://components-and-props/composing-components)

Typically, new React apps have a single `App` component at the very top. However, if you integrate React into an existing app, you might start bottom-up with a small component like `Button` and gradually work your way to the top of the view hierarchy.

Expand Down Expand Up @@ -152,7 +152,7 @@ function Comment(props) {
}
```

[](codepen://components-and-props/extracting-components).
[](codepen://components-and-props/extracting-components)

It accepts `author` (an object), `text` (a string), and `date` (a date) as props, and describes a comment on a social media website.

Expand Down Expand Up @@ -231,7 +231,7 @@ function Comment(props) {
}
```

[](codepen://components-and-props/extracting-components-continued).
[](codepen://components-and-props/extracting-components-continued)

Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (`Button`, `Panel`, `Avatar`), or is complex enough on its own (`App`, `FeedStory`, `Comment`), it is a good candidate to be a reusable component.

Expand Down
8 changes: 4 additions & 4 deletions content/docs/composition-vs-inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function WelcomeDialog() {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/ozqNOV?editors=0010)
**[Try it on CodePen](https://codepen.io/gaearon/pen/ozqNOV?editors=0010)**

Anything inside the `<FancyBorder>` JSX tag gets passed into the `FancyBorder` component as a `children` prop. Since `FancyBorder` renders `{props.children}` inside a `<div>`, the passed elements appear in the final output.

Expand Down Expand Up @@ -77,7 +77,7 @@ function App() {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/gwZOJp?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/gwZOJp?editors=0010)

React elements like `<Contacts />` and `<Chat />` are just objects, so you can pass them as props like any other data. This approach may remind you of "slots" in other libraries but there are no limitations on what you can pass as props in React.

Expand Down Expand Up @@ -110,7 +110,7 @@ function WelcomeDialog() {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/kkEaOZ?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/kkEaOZ?editors=0010)

Composition works equally well for components defined as classes:

Expand Down Expand Up @@ -160,7 +160,7 @@ class SignUpDialog extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/gwZbYa?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/gwZbYa?editors=0010)

## So What About Inheritance?

Expand Down
8 changes: 4 additions & 4 deletions content/docs/conditional-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)

This example renders a different greeting depending on the value of `isLoggedIn` prop.

Expand Down Expand Up @@ -115,7 +115,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)

While declaring a variable and using an `if` statement is a fine way to conditionally render a component, sometimes you might want to use a shorter syntax. There are a few ways to inline conditions in JSX, explained below.

Expand Down Expand Up @@ -145,7 +145,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)

It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.

Expand Down Expand Up @@ -237,6 +237,6 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)

Returning `null` from a component's `render` method does not affect the firing of the component's lifecycle methods. For instance `componentDidUpdate` will still be called.
6 changes: 3 additions & 3 deletions content/docs/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class NameForm extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/VmmPgp?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/VmmPgp?editors=0010)

Since the `value` attribute is set on our form element, the displayed value will always be `this.state.value`, making the React state the source of truth. Since `handleChange` runs on every keystroke to update the React state, the displayed value will update as the user types.

Expand Down Expand Up @@ -178,7 +178,7 @@ class FlavorForm extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/JbbEzX?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/JbbEzX?editors=0010)

Overall, this makes it so that `<input type="text">`, `<textarea>`, and `<select>` all work very similarly - they all accept a `value` attribute that you can use to implement a controlled component.

Expand Down Expand Up @@ -254,7 +254,7 @@ class Reservation extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/wgedvV?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/wgedvV?editors=0010)

Note how we used the ES6 [computed property name](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) syntax to update the state key corresponding to the given input name:

Expand Down
2 changes: 1 addition & 1 deletion content/docs/handling-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/xEmzGg?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010)

You have to be careful about the meaning of `this` in JSX callbacks. In JavaScript, class methods are not [bound](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind) by default. If you forget to bind `this.handleClick` and pass it to `onClick`, `this` will be `undefined` when the function is actually called.

Expand Down
14 changes: 7 additions & 7 deletions content/docs/integrating-with-other-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ componentWillUnmount() {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/qmqeQx?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/qmqeQx?editors=0010)

Note that React assigns no special meaning to the `this.el` field. It only works because we have previously assigned this field from a `ref` in the `render()` method:

Expand Down Expand Up @@ -131,7 +131,7 @@ handleChange(e) {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/bWgbeE?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/bWgbeE?editors=0010)

Finally, there is one more thing left to do. In React, props can change over time. For example, the `<Chosen>` component can get different children if parent component's state changes. This means that at integration points it is important that we manually update the DOM in response to prop updates, since we no longer let React manage the DOM for us.

Expand Down Expand Up @@ -186,7 +186,7 @@ class Chosen extends React.Component {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/xdgKOz?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/xdgKOz?editors=0010)

## Integrating with Other View Libraries

Expand Down Expand Up @@ -247,7 +247,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/RVKbvW?editors=1010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/RVKbvW?editors=1010)

You can have as many such isolated components as you like, and use `ReactDOM.render()` to render them to different DOM containers. Gradually, as you convert more of your app to React, you will be able to combine them into larger components, and move some of the `ReactDOM.render()` calls up the hierarchy.

Expand Down Expand Up @@ -275,7 +275,7 @@ const ParagraphView = Backbone.View.extend({
});
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/gWgOYL?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/gWgOYL?editors=0010)

It is important that we also call `ReactDOM.unmountComponentAtNode()` in the `remove` method so that React unregisters event handlers and other resources associated with the component tree when it is detached.

Expand Down Expand Up @@ -347,7 +347,7 @@ class List extends React.Component {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/GmrREm?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/GmrREm?editors=0010)

### Extracting Data from Backbone Models

Expand Down Expand Up @@ -434,6 +434,6 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/PmWwwa?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/PmWwwa?editors=0010)

This technique is not limited to Backbone. You can use React with any model library by subscribing to its changes in the lifecycle hooks and, optionally, copying the data into the local React state.
2 changes: 1 addition & 1 deletion content/docs/introducing-jsx.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ReactDOM.render(
);
```

[](codepen://introducing-jsx).
[](codepen://introducing-jsx)

We split JSX over multiple lines for readability. While it isn't required, when doing this, we also recommend wrapping it in parentheses to avoid the pitfalls of [automatic semicolon insertion](http://stackoverflow.com/q/2846283).

Expand Down
6 changes: 3 additions & 3 deletions content/docs/lifting-state-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Calculator extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/ZXeOBm?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOBm?editors=0010)

## Adding a Second Input

Expand Down Expand Up @@ -110,7 +110,7 @@ class Calculator extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/jGBryx?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBryx?editors=0010)

We have two inputs now, but when you enter the temperature in one of them, the other doesn't update. This contradicts our requirement: we want to keep them in sync.

Expand Down Expand Up @@ -299,7 +299,7 @@ class Calculator extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/WZpxpz?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/WZpxpz?editors=0010)

Now, no matter which input you edit, `this.state.temperature` and `this.state.scale` in the `Calculator` get updated. One of the inputs gets the value as is, so any user input is preserved, and the other input value is always recalculated based on it.

Expand Down
10 changes: 5 additions & 5 deletions content/docs/lists-and-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)

This code displays a bullet list of numbers between 1 and 5.

Expand Down Expand Up @@ -94,7 +94,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)

## Keys

Expand Down Expand Up @@ -202,7 +202,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)

A good rule of thumb is that elements inside the `map()` call need keys.

Expand Down Expand Up @@ -246,7 +246,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)

Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:

Expand Down Expand Up @@ -296,6 +296,6 @@ function NumberList(props) {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)

Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the `map()` body is too nested, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
4 changes: 2 additions & 2 deletions content/docs/portals.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A typical use case for portals is when a parent component has an `overflow: hidd
>
> It is important to remember, when working with portals, you'll need to make sure to follow the proper accessibility guidelines.
[Try it on CodePen.](https://codepen.io/gaearon/pen/yzMaBd)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/yzMaBd)

## Event Bubbling Through Portals

Expand Down Expand Up @@ -147,6 +147,6 @@ function Child() {
ReactDOM.render(<Parent />, appRoot);
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/jGBWpE)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBWpE)

Catching an event bubbling up from a portal in a parent component allows the development of more flexible abstractions that are not inherently reliant on portals. For example, if you render a `<Modal />` component, the parent can capture its events regardless of whether it's implemented using portals.
14 changes: 7 additions & 7 deletions content/docs/state-and-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function tick() {
setInterval(tick, 1000);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/gwoJZk?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/gwoJZk?editors=0010)

In this section, we will learn how to make the `Clock` component truly reusable and encapsulated. It will set up its own timer and update itself every second.

Expand All @@ -54,7 +54,7 @@ function tick() {
setInterval(tick, 1000);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/dpdoYR?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/dpdoYR?editors=0010)

However, it misses a crucial requirement: the fact that the `Clock` sets up a timer and updates the UI every second should be an implementation detail of the `Clock`.

Expand Down Expand Up @@ -100,7 +100,7 @@ class Clock extends React.Component {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/zKRGpo?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/zKRGpo?editors=0010)

`Clock` is now defined as a class rather than a function.

Expand Down Expand Up @@ -192,7 +192,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/KgQpJd?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/KgQpJd?editors=0010)

Next, we'll make the `Clock` set up its own timer and update itself every second.

Expand Down Expand Up @@ -301,7 +301,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/amqdNA?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/amqdNA?editors=0010)

Now the clock ticks every second.

Expand Down Expand Up @@ -436,7 +436,7 @@ function FormattedDate(props) {
}
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/zKRqNB?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/zKRqNB?editors=0010)

This is commonly called a "top-down" or "unidirectional" data flow. Any state is always owned by some specific component, and any data or UI derived from that state can only affect components "below" them in the tree.

Expand All @@ -461,7 +461,7 @@ ReactDOM.render(
);
```

[Try it on CodePen.](http://codepen.io/gaearon/pen/vXdGmd?editors=0010)
[**Try it on CodePen**](http://codepen.io/gaearon/pen/vXdGmd?editors=0010)

Each `Clock` sets up its own timer and updates independently.

Expand Down
4 changes: 2 additions & 2 deletions content/docs/uncontrolled-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NameForm extends React.Component {
}
```

[Try it on CodePen.](https://codepen.io/gaearon/pen/WooRWa?editors=0010)
[**Try it on CodePen**](https://codepen.io/gaearon/pen/WooRWa?editors=0010)

Since an uncontrolled component keeps the source of truth in the DOM, it is sometimes easier to integrate React and non-React code when using uncontrolled components. It can also be slightly less code if you want to be quick and dirty. Otherwise, you should usually use controlled components.

Expand Down Expand Up @@ -80,5 +80,5 @@ You should use the File API to interact with the files. The following example sh

`embed:uncontrolled-components/input-type-file.js`

[Try it on CodePen](codepen://uncontrolled-components/input-type-file)
[](codepen://uncontrolled-components/input-type-file)

Loading

0 comments on commit db66436

Please sign in to comment.