diff --git a/docs/data-fetching.md b/docs/data-fetching.md index b1d3919ef..cdb0eb9e5 100644 --- a/docs/data-fetching.md +++ b/docs/data-fetching.md @@ -41,14 +41,22 @@ React components as follows: #### React Component ```js -class Post extends React.Component { - static contextTypes = { fetch: PropTypes.func.isRequired }; - handleDelete = (event) => { - event.preventDefault(); - const id = event.target.dataset['id']; - this.context.fetch(`/api/posts/${id}`, { method: 'DELETE' }).then(...); - }; - render() { ... } +import {useContext} from 'react'; +import ApplicationContext from '../ApplicationContext'; + +function Post() { + const {context} = useContext(ApplicationContext); + return ( +
+ ... + { + event.preventDefault(); + const id = event.target.dataset['id']; + // Use context.fetch to make it work in both server-side and client-side + context.fetch(`/api/posts/${id}`, { method: 'DELETE' }).then(...); + }}>Delete +
+ ); } ``` diff --git a/docs/react-style-guide.md b/docs/react-style-guide.md index 745b45d3f..c4d71fe53 100644 --- a/docs/react-style-guide.md +++ b/docs/react-style-guide.md @@ -127,10 +127,11 @@ Navigation.propTypes = { items: PropTypes.array.isRequired }; // Navigation.js import React from 'react'; import PropTypes from 'prop-types'; -import withStyles from 'isomorphic-style-loader/withStyles'; +import useStyles from 'isomorphic-style-loader/useStyles'; import s from './Navigation.scss'; -function Navigation() { +export default function Navigation() { + useStyles(s); return (