tkh44/holen

Holen's `fetch` can call `setState` within `render`

jamesplease opened this issue · 0 comments

React does not permit you to call setState within render. However, Holen allows you to do this via code such as:

<Holen
  {...stuff}
  render={({ fetch }) => fetch()} />

Clearly, nobody would write code exactly like this example, but you can imagine someone conditionally firing a request when the component calls render (i.e.; with use cases such as the one described in #20 )

This isn't the biggest issue ever, but I think we could help improve the situation through one of two ways:

  1. wrap the fetch that is passed into render in a setTimeout. This way, developers do not need to worry about anything. This makes testing the lib harder, though

  2. Add a note to the README to let people know not to do this. This is absolutely an edge-case thing, but people do some weird things sometimes 🙂


I need to verify the behavior of this code but my prediction is that React just ignores the synchronous setState call within render to prevent an infinite loop. If this is the behavior, then the consequence is that the component would fire off the request but not store that the request is in flight.