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

绑定数据,星级不跟随数据变化 #1

Open
chenyinlong opened this issue Oct 11, 2018 · 3 comments
Open

绑定数据,星级不跟随数据变化 #1

chenyinlong opened this issue Oct 11, 2018 · 3 comments

Comments

@chenyinlong
Copy link

查看源码:
this.state = { rating: props.rating || 0 };
你将props数据赋值在state上,造成不能辩护;
请更新代码
`render() {
let extraProps = this.props.viewOnly ? {} : this.panResponder.panHandlers;

return (
  <View
    onLayout={event => {
      const layout = event.nativeEvent.layout;
      this.viewX = layout.x;
    }}
    style={{ flexDirection: 'row' }}
    {...extraProps}
  >
    // {this._getStars(this.state.rating)}
     {this._getStars(this.props.rating)}
  </View>
);

}`

@DevAlien
Copy link
Owner

Could you please write in English?

@chenyinlong
Copy link
Author

Yes,First of all, I thank you for this lib.
When I'm in use, I want the stars to follow the data to change, but it doesn't work,
when I look at the code.
i see line 9

this.state = { rating: props.rating || 0 };

Maybe it makes the stars unable to change?

so i change line 29

{this._getStars(this.props.rating)}

@DevAlien
Copy link
Owner

The idea is to let the component set the number of stars after the initial render. And you get the value of it via onChange.

So you would like to set the prop all the time with the value. The thing is, how does that get set?

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

No branches or pull requests

2 participants