import React from 'react';
import ReactDOM from "react-dom"

// Array solution to call multiple useState
let state = []
let setters = []
let stateIndex = 0

// The function calls itself
function createSetter (index) {
  return function (newState) {
    state[index] = newState
    render()
  }
}

function useState (initialState) {
  / / assignment state [stateIndex]
  state[stateIndex] = state[stateIndex] ? state[stateIndex] : initialState
  setters.push(createSetter(stateIndex))
  let value = state[stateIndex]
  let setter = setters[stateIndex]
  stateIndex++
  return [value, setter]
}

/ / update the DOM
function render () {
  stateIndex = 0 / / to zero

  // React.StrictMode Does not update the view after the first render/page refresh

  ReactDOM.render(<React.StrictMode>
    <App />
  </React.StrictMode>.document.getElementById('root'))

  console.log('ss')}function App () {
  const [count, setCount] = useState(0)
  const [name, setName] = useState('ul')

  return (
    <div className="App">
      {count}
      <button onClick={()= > setCount(count + 1)}> setCount </button>
      {name}
      <button onClick={()= > setName('li')}> setName </button>
    </div>
  );
}

export default App;

Copy the code