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

Pass props to valueComponent #1208

Closed
mehrdad-shokri opened this issue Sep 11, 2016 · 2 comments
Closed

Pass props to valueComponent #1208

mehrdad-shokri opened this issue Sep 11, 2016 · 2 comments

Comments

@mehrdad-shokri
Copy link

in my Select component I have sth like:

<Select
valueComponent={GravatarValue}
                            />

My problem is that I can't pass props to GravatarValue. how can I do that?

@bvaughn
Copy link
Collaborator

bvaughn commented Sep 11, 2016

You could use an approach like this:

function createGravatarValue (yourProps) {
  return function GravatarValueWrapper (selectProps) {
    // Has access to all your custom props (yourProps)
    // As well as those provided by Select (selectProps)
    return (
      <GravatarValue
        {...yourProps}
        {...selectProps}
      />
    )
  }
}

function createSelect (selectProps) {
  const GravatarValueWrapper = createGravatarValue({
    // Whatever props you want to pass outside of Select
  })

  return (
    <Select
      {...selectProps}
      valueComponent={GravatarValueWrapper}
    />
  )
}

@bvaughn
Copy link
Collaborator

bvaughn commented Sep 11, 2016

Essentially, wrap the props you want to pass (outside of Select) up in a closure and then stitch them together with props from Select and pass both along to GravatarValue (or whatever value renderer you're using).

Cheers!

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