drcmda / react-contextual

🚀 react-contextual is a small (less than 1KB) helper around React 16s new context api
MIT License
642 stars 23 forks source link

Typo on context check #30

Closed msssk closed 5 years ago

msssk commented 5 years ago

Lines 61-62 in store.js don't seem to make sense:

if (!store)
  this.store.context = id ? createNamedContext(id) : ProviderContext

Should 61 be changed?

if (!store.context)
drcmda commented 5 years ago

looks good to me, if no external store is passed a context is created either by id or the default.

smeijer commented 5 years ago

Looks good indeed; The issue just needs a little more context.

https://github.com/drcmda/react-contextual/blob/2f4bec2f5fc3bd58bc044f1739b73f7b63407b86/src/store.js#L58:L62

store can still be undefined here, but this.store has been initialized one line before the if. Because there was no store provided to the contructor, the next thing to do is, assign this store a new context. Its like @drcmda writes, either done with createNamedContext or ProviderContext depending on the given arguments (id).