Skip to content

Conversation

shammamah-zz
Copy link
Contributor

@shammamah-zz shammamah-zz commented Apr 9, 2019

Closes #310

About

  • This is a new component
  • I am adding a feature to an existing component, or improving an existing feature
  • I am closing an issue

Description of changes

This issue was due to the fact that loadStructure was not being called from componentDidMount, and instead only from componentDidUpdate. I also ran into an issue where loadStructure failed because this.state.renderer was still null, even after having defined it -- this was because setState does not immediately mutate the state of the component (https://reactjs.org/docs/react-component.html#setstate). From the documentation:

setState() does not always immediately update the component. It may batch or defer the update until later. This makes reading this.state right after calling setState() a potential pitfall. Instead, use componentDidUpdate or a setState callback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied. If you need to set the state based on the previous state, read about the updater argument below.

I therefore added a callback to call loadStructure() only after the renderer had been updated to a non-null value.

Before merging

@shammamah-zz shammamah-zz merged commit bbd8621 into master Apr 10, 2019
@shammamah-zz shammamah-zz deleted the speck-component-rendering-fix branch April 10, 2019 16:21
@shammamah-zz shammamah-zz mentioned this pull request Apr 10, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants