question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Name of the Picker?

See original GitHub issue

I saw the merge where you can now pass up the event with the onChange handler, so I’m just having trouble actually getting the name of the picker I want to see. This is what I currently have for the Picker right now (which is mainly taken from docs):

{ (this.state.displayColorPicker) ?
          <div style={ styles.popover }>
            <div style={ styles.cover } onClick={ this.handleClose }></div>
          <SketchPicker color={ this.state.color } label="bgColor" onChange={ this.props.onChange } name={this.props.name} />
          </div> : null }

And my onChange is as such:

  handleColorChange(color, event) {
    const target = event.target;
    const name = target.name;

    console.log("NAME: " + name)
    console.log("COLOR CHANGING:" + JSON.stringify(color))

    // this.setState({ color: color.hex })
  };

I can succesfully get the color information, I’m just stuck on trying to get which color should go where. Feeling like I’m probably missing a very basic step here. 😕

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
casesandbergcommented, May 25, 2017

I have thought about this and I don’t think adding this complexity to the library makes sense. What I propose is just using a curry function like below to pass the names of multiple pickers:

const handleColorChange = (name) => (color) => {
  this.setState({ name, color: color.hex })
}

and then you would use it like this:

<SketchPicker onChange={ handleColorChange('foreground') } />
<SketchPicker onChange={ handleColorChange('background') } />

The handleColorChange would take the name as the first argument and then retuns the traditional change information, along with the name.

1reaction
tmercadocommented, Nov 1, 2018

Not sure if anyone is still following this but doesn’t currying a function like that create copies of the handleColorChange function? so if you are mapping say 1000 things that could have a color changing option you’ll start to have performance issues.

changeHandler => name => color {
    const {pickers} = this.state;
    pickers[name] = color;
    this.setState({pickers});
}
this.state.pickers.map((p, i) => ( // I have 1000+ pickers to create
    <SketchPicker onChange={this.changeHandler('i')} value={p.color} />
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pick a random name / winner - Comment Picker
Name Picker is an easy-to-use online tool to quickly draw a random name from a list of names and instantly pick a winner....
Read more >
Random Name Picker | Spin The Wheel to Pick The Winner
This Free & ᴇᴀsʏ⁻ᵗᵒ⁻ᵘˢᵉ tool allows you to pick a random name (winner) from a list of names (it supports up to 200k...
Read more >
Wheel of Names | Random name picker
Free and easy to use spinner. Used by teachers and for raffles. Enter names and spin the wheel to pick a random winner....
Read more >
Easy Random Name Picker - Random Word Generator
The Random Name Generator creates random names including girl names, boy names, baby names and last names. Use this random name picker to...
Read more >
Random Name Picker - Microsoft Apps
Description. Picks a random name from a list of names. The App supports custom backgrounds so you can show it to your audience...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found