Created
January 27, 2019 22:59
My react cheat sheet
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 * as React from 'react'; | |
// --- Component ---------------------------------------------------------------------------------- | |
type HelloProps = {}; | |
type HelloState = {}; | |
class Hello extends React.Component<HelloProps, HelloState> { | |
readonly state = {}; | |
constructor(props) { super(props) } | |
render() { | |
return ( | |
<div>Hello world</div> | |
) | |
} | |
} | |
// --- Functional --------------------------------------------------------------------------------- | |
const Hello: React.FunctionComponent<HelloProps> = ({ }) => ( | |
<div>Hello world</div> | |
); | |
const Hello = () => ( | |
<div>Hello world</div> | |
); | |
// --- Higher Order Components -------------------------------------------------------------------- | |
const HOC = WrappedComponent => { | |
return (props = {}) => { | |
return (<WrappedComponent {...props} />); | |
} | |
} | |
const HOC = WrappedComponent => props => ( | |
<WrappedComponent {...props} /> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment