Browse Source

Use function keyword

main
Alex Krolick 7 years ago
parent
commit
3c44882d68
  1. 8
      examples/context/motivation-problem.js
  2. 10
      examples/context/motivation-solution.js
  3. 4
      examples/context/multiple-contexts.js
  4. 4
      examples/context/theme-detailed-app.js

8
examples/context/motivation-problem.js

@ -1,10 +1,10 @@
const ThemedButton = props => {
function ThemedButton(props) {
//highlight-range{1}
return <Button theme={props.theme} />;
};
}
// An intermediate component
const Toolbar = props => {
function Toolbar(props) {
// highlight-range{1-2,5}
// The Toolbar component must take an extra theme prop
// and pass it to the ThemedButton
@ -13,7 +13,7 @@ const Toolbar = props => {
<ThemedButton theme={props.theme} />
</div>
);
};
}
class App extends React.Component {
render() {

10
examples/context/motivation-solution.js

@ -2,24 +2,24 @@
// highlight-next-line
const ThemeContext = React.createContext('light');
const ThemedButton = props => {
function ThemedButton(props) {
// highlight-range{1,3-5}
// The ThemedButton receives the theme from context
return (
<ThemeContext.Consumer>
{theme => <Button theme={theme} />}
{theme => <Button {...props} theme={theme} />}
</ThemeContext.Consumer>
);
};
}
// An intermediate component
const Toolbar = props => {
function Toolbar(props) {
return (
<div>
<ThemedButton />
</div>
);
};
}
class App extends React.Component {
render() {

4
examples/context/multiple-contexts.js

@ -7,7 +7,7 @@ const ThemeContext = React.createContext('light');
const UserContext = React.createContext();
// An intermediate component that depends on both contexts
const Toolbar = props => {
function Toolbar(props) {
// highlight-range{2-10}
return (
<ThemeContext.Consumer>
@ -20,7 +20,7 @@ const Toolbar = props => {
)}
</ThemeContext.Consumer>
);
};
}
class App extends React.Component {
static propTypes = {

4
examples/context/theme-detailed-app.js

@ -2,13 +2,13 @@ import {ThemeContext, themes} from './theme-context';
import ThemedButton from './button';
// An intermediate component that uses the ThemedButton
const Toolbar = props => {
function Toolbar(props) {
return (
<ThemedButton onClick={props.changeTheme}>
Change Theme
</ThemedButton>
);
};
}
class App extends React.Component {
state = {

Loading…
Cancel
Save