title: how to handle synchronization of resource on create
body: <p>I'm working with react and redux (connected to a server), and I'm having trouble on how to initialize a resource so that changes can be tracked by different components.</p>
  
  <p>Initial state for the store:</p>
  
  <pre><code>{
    user: {
      1: {
        name: 'Jun Hanamaki',
      },
      2: {
        name: 'Michael Jordan',
      }
    }
    cars: {
      1: {
        owner_id: 1,
        description: 'This car is red and rides fast!',
      }
    },
  }
  </code></pre>
  
  <p>So I have a list of users that can own cars, nothing special. Now my situation is, I want to create a new car (this would be a form component), but keep the changes in the store so that the user can navigate to other pages, without losing the data that was already inserted. I also I want these changes to be visible from another component that displays the description and that resides in a sidebar.</p>
  
  <p>Layout would be something like this (A is the form where user edits the car attributes, B is the sidebar that shows the description that is being edited in the form):</p>
  
  <pre><code>-----------------
  |           |   |
  |    A      | B |
  |           |   |
  -----------------
  </code></pre>
  
  <p>Now this would be trivial to do for something that already exists, like editing the car with id 1, since we would just require for both components to be connected and to get the car with id 1. But my problem is how to do this for something that has no id, since how does the sidebar track changes for something that has no id?</p>
  
  <p>I can see two solutions to generate id:</p>
  
  <ul>
  <li><p>ask server to create a car and use returned id, this doesn't look good because server must be able to initialize an empty resource (which may not be possible given business rules), and we're creating a resource that may end being discarded;</p></li>
  <li><p>create the car on client side and use that, this means that the server would persist the resource using this id (is this reliable?);</p></li>
  </ul>
  
  <p>How should one approach this problem?</p>
  
  <p>Thank you for your attention.</p>
  
  <p>EDIT:</p>
  
  <p>Sorry for taking so long to answer.</p>
  
  <p>We ended up agreeing in following Dan's suggestion, as in we'll generate the id of the resource in the browser, being the effective id of the resource.</p>
  
  <p>Thank you all for your attention.</p>