Skip to content

Instantly share code, notes, and snippets.

Fendy Heryanto fendy3002

Block or report user

Report or block fendy3002

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fendy3002
fendy3002 / FriendStatus.js
Last active Oct 27, 2018
My version of React Hook
View FriendStatus.js
const FriendStatus = React.createClass(
// param pos 1, the render
(props, state, hooks) => {
const isOnline = hooks[0];
if (isOnline === null) {
return 'Loading...';
}
// the component to render
return isOnline ? 'Online' : 'Offline';
View ReactHookManipulateOtherHookState.js
let useCustom1 = (parentCount) => {
let [count, setCount] = useState(10);
console.log("custom1", count);
useEffect(() => {
setCount(count + 1);
}, [parentCount]);
return count;
};
let useCustom2 = () => {
// will refer to state for useCustom1
View ReactHookEffectPooling.js
export default (() => {
let [count, setCount] = useState(0);
if(count <= 2){
useEffect(() => {
console.log(count);
});
/* if enabled, will error because less hook executed on else clause*/
/*
useEffect(() => {
View init.coffee
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
You can’t perform that action at this time.