title: How to re-render after state is changed in react js?
body: <pre><code>import React from 'react'
  
  export default function App(){
      const[flag,setFlag] =React.useState({1:false,2:false})
  
      const change=(id)=&gt;{
          flag[id] = !flag[id]
          setFlag(flag)
          console.log(flag)
      }
  
      return(
          &lt;div&gt;
              {flag[1] ? &lt;p&gt;this is true&lt;/p&gt; : &lt;p&gt;this is false&lt;/p&gt;}
              &lt;button onClick={()=&gt;change(1)}&gt;Change&lt;/button&gt;
          &lt;/div&gt;
      )
  }
  </code></pre>
  
  <p>I want to change my output based on flag state. While flag JSON is changing, but it's not re-rendering.</p>