pauldotknopf / react-aspnet-boilerplate

A starting point for building isomorphic React applications with ASP.NET Core, leveraging existing techniques.
MIT License
288 stars 52 forks source link

Showcase a GET example rendered server/client side? #3

Closed jcd79 closed 8 years ago

jcd79 commented 8 years ago

I've started working with you template.

It's not completely clear for me how it's supposed to work with GET calls and pre-rendered data.

I've made it work like this - but it feels somehow awkward.

  1. Server side - in view controller fill state.someData = SomeObject();
  2. Client side - pass dispatcher in Connect and call dispatcher in componentDidMount() if !state.someData?
pauldotknopf commented 8 years ago

I will add an example to make this more clear.

In the mean time, you are probably missing a reducer. You are correctly sending the state to the client, but when that state is passed to the store and an action is finally dispatched, the data is dropped off because it wasn't handled by a reducer.

You will want to modify the reducer.js file to handle someData.

If you notice, there is temp property on the state. Notice a few things on it.

  1. It has an empty reducer.
  2. It is in the StateViewModel here so that controllers can set it.
  3. It is set from a controller and used on the client via state.temp.{property}

I am using the temp state for any random data that I need sent to the server, but I don't want to do the entire plumbing because it doesn't really do anything advanced. I will probally replace this temp state with a viewBag, that will be populated from MVC using the ViewBag. This will give users ability to send generic data to the client that doesn't really transform via reducer actions.

If you need to send some custom state to the client and reducer actions need to be performed on it, then you will want to setup a reducer specifically for the data, such as the auth.js.

You are correct though. There needs to be clear documentation for this. I will create a Wiki page going through this. I will ping this ticket when I am done. I'll get to it this weekend.

pauldotknopf commented 8 years ago

Update! I pushed an example to help you get started!

This example is in the empty-template branch. Look specifically at commit a39add4.