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

feat(core): expanded attach #31

Merged
merged 1 commit into from
May 30, 2022
Merged

feat(core): expanded attach #31

merged 1 commit into from
May 30, 2022

Conversation

CodyJasonBennett
Copy link
Member

Expands the attach prop by accepting an attach function in addition to a string. This is 1-1 with R3F v8's unified attach API.

// will attach to parent.target
<parent>
  <child attach="target" />
</parent>

// will attach to parent.target.subtarget
<parent>
  <child attach="target-subtarget" />
</parent>

// will attach to parent.target[0] and parent.target[1], creates an array if parent.target is undefined
// useful for attaching multiple elements to an array
<parent>
  <child attach="target-0" />
  <child attach="target-1" />
</parent>

// will call child.setParent on mount and child.removeChild unmount
<parent>
  <child
    attach={(parent, self) => {
      self.setParent(parent)
      // remove on unmount
      return () => parent.removeChild(self)
    }}
  />
</parent>

@CodyJasonBennett CodyJasonBennett merged commit 7d71d89 into main May 30, 2022
@CodyJasonBennett CodyJasonBennett deleted the feat-expanded-attach branch May 30, 2022 09:45
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.

1 participant