Last active
February 9, 2019 14:07
-
-
Save hckhanh/aadce447470103da25e329e5254e4615 to your computer and use it in GitHub Desktop.
Use useState instead of class component
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, { useState } from "react"; | |
import DataSource from "../DataSource"; | |
const TextBlock = ({ text }) => <>{text}</>; | |
export function BlogPost({ id }) { | |
// State is declared in pair: state value and setState function | |
const [data, setData] = useState(DataSource.getBlogPost(id)); | |
return <TextBlock text={data} />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment