Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching between components ref element stop working #647

Closed
nahumzs opened this issue Dec 12, 2016 · 2 comments
Closed

Switching between components ref element stop working #647

nahumzs opened this issue Dec 12, 2016 · 2 comments

Comments

@nahumzs
Copy link

nahumzs commented Dec 12, 2016

I'm using ref={ e=>this.element = e} element to helped me to calculate a position absolute of a menu below a button/link when I run the story with focus in the current story, everything works without problem, but if I switch between components and then click again in that specific story the ref don't fire again and the element is always is undefined and because I'm validating to render the component until element !== undefined my component don't get render, I'm attaching a gif image with the behaviour.

pillvoterissue

a piece of my code

  renderMenu() {
    if (this.$element && this.props.menuList.length > 0 && !this.state.menuCollapse) {
      return (
        <PillMenu
          menuList={this.props.menuList}
          container={this.$element}
          collapse={this.state.menuCollapse}
          onMaskClicked={() => this.setState({ menuCollapse: true })}
          onChange={newValue => this.onChange(newValue)}
        />
      );
    }
    return '';
  }

render() {
  ...
  {this.renderMenu()}
  ...
}

any idea what could be happening?

@arunoda
Copy link
Member

arunoda commented Dec 15, 2016

I think we run a fresh component when switching stories.
So, every time it runs with a new instance of your component.

It's really hard for me to tell more about based on this info. If you could create a minimal repo isolating the core problem, I could have a look at it.

@nahumzs
Copy link
Author

nahumzs commented Dec 18, 2016

apparently was my mistake, storybook is working correctly again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants