Skip to content

Instantly share code, notes, and snippets.

@steida
Created June 23, 2016 00:24
Show Gist options
  • Save steida/ab60102ecee2591aec1cb269333af099 to your computer and use it in GitHub Desktop.
Save steida/ab60102ecee2591aec1cb269333af099 to your computer and use it in GitHub Desktop.
React stateless components with lifecycle proposal
const HelloMessage = props =>
<div>Hello {props.name}</div>;
{
let isMounted = false;
const focusAfterAfterOneSec = el => {
setTimeout(() => {
if (!isMounted) return;
el.focus();
}, 1000);
}
HelloMessage.componentDidMount = el => {
isMounted = true;
focusAfterAfterOneSec(el);
};
HelloMessage.componentWillUnmount = el => {
isMounted = false;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment