js-libs-react

import KoshContext from "./KoshContext"
 
const KoshResultParams = () => {
  // Declare context
  const state = useContext(KoshContext)
  // Set default state value
  const [targets, setTargets] = useState(state.results.display_fields) 
  const handleChange = (e, v) => {
    setTargets(prevTargets => ({
      ...prevTargets,
      [v]: e.target.checked
    }))
  }

useState() is run asynchronous. That’s why the changes are not immediately reflected through console.log()