Created
April 24, 2020 18:40
-
-
Save kalysr/460596a1e77c0ae7100bc2f3a3385314 to your computer and use it in GitHub Desktop.
This file contains 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
let index = 0; | |
let defaultState = []; | |
const useState = (state) => { | |
index++; | |
if (defaultState[index] === undefined) { | |
defaultState[index] = state; | |
} | |
const setState = (newState) => { | |
defaultState[index] = newState; | |
}; | |
return [defaultState[index], setState]; | |
}; | |
function Component1() { | |
const [inputValue, setInputValue] = useState(0); | |
setInputValue(inputValue + 1); | |
console.log("inputValue:", inputValue); | |
} | |
function Component2() { | |
const [inputValue, setInputValue] = useState(0); | |
setInputValue(inputValue + 1); | |
console.log("inputValue:", inputValue); | |
} | |
function Component3() { | |
const [inputValue, setInputValue] = useState(0); | |
setInputValue(inputValue + 1); | |
console.log("inputValue:", inputValue); | |
} | |
function render(){ | |
Component1(); | |
Component2(); | |
Component3(); | |
index = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment