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

Fix passing undefined #93

Closed
wants to merge 3 commits into from
Closed

Fix passing undefined #93

wants to merge 3 commits into from

Conversation

browniefed
Copy link
Member

No description provided.

const { style, ...other} = this._propsAnimated.__getValue();
const props = this._propsAnimated.__getValue();
if (props.style) {
props.style = ApplyAnimatedValues.transformStyles(props.style)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change mutates the object, previously it did not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I realize that, but attempting to avoid an if statement with rendering the component and or creating another new object to spread on w/ props.
The __getValue always returns a new object https://github.com/animatedjs/animated/blob/master/src/AnimatedProps.js#L37

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Why avoid an if statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, personal preference.
Generally speaking I like my render functions to have a single return.

render() {
      const props = this._propsAnimated.__getValue();
      if (props.style) {
        return (
          <Component
            {...props}
            style={ApplyAnimatedValues.transformStyles(props.style)}
            ref={refName}
          />
        );
      }

      return <Component {...props} ref={refName} />;
    }

This is fine by me, accomplishes the same thing.

@browniefed
Copy link
Member Author

@ljharb Let me know if this fix works for your system and we can merge and release it.

@browniefed browniefed closed this Aug 10, 2022
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