title: Fast Refresh + Update function implementation of object that is in React state
body: <p>assuming I have a React app that has a internal state where I store an object like</p>
  <pre><code>  const [car, setCar] = useState(new Car());
  </code></pre>
  <p>Assuming my class Car looks like the following:</p>
  <pre><code>class Car {
    constructor(brand) {
      this.carname = brand;
    }
  
    present() {
      return &quot;I have a &quot; + this.carname;
    }
  }
  </code></pre>
  <p>When I run and debug the app, I can save a Car object into the state and also retrieve it and call present().</p>
  <p>Now, when I make changes to the present() function, e.g.</p>
  <pre><code>  present() {
      return &quot;I have a &quot; + this.carname + &quot; and it is shiny&quot;;
    }
  </code></pre>
  <p>then due to Fast Refresh my App gets refreshed. But unfortunately, because the object is already stored in state, it will not receive the update of the function implementation.</p>
  <p>Is there a way that I can change the code so that with a Fast Refresh the function implementation will be updated also for the object in React state?</p>
  <p>I tried updating the method via prototype but it did also not work.</p>