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

Color pointer not resetting after color change #193

Open
grantspilsbury opened this issue Sep 13, 2022 · 1 comment
Open

Color pointer not resetting after color change #193

grantspilsbury opened this issue Sep 13, 2022 · 1 comment

Comments

@grantspilsbury
Copy link

grantspilsbury commented Sep 13, 2022

I am trying to reset the color pointer button after I click a button but the pointer remains the previously selected color.

In the example below I expect the color pointer to change to white (not green, and be in the correct position) after the Set button is clicked.

const Panel = () => {
  const [color, setColor] = useState('white')
  const handleColorChange = (color) => setColor(color)

  return (
	<>
	  <HexColorPicker color={color} onChange={handleColorChange} />
	  <button onClick={() => setColor('white')}>
	      Set
	  </button>
	</>
  )
}
export default Panel

What am I doing wrong?

Screen Shot 2022-09-13 at 9 00 51 am

@GabrielModog
Copy link

GabrielModog commented Oct 23, 2022

Hi Grant! Are you good? Hope you going well!

This can be solved by adding hex color instead of the color name. You are importing a component that handles with hex color only.

const Panel = () => {
  const [color, setColor] = useState("#ffffff");
  const handleColorChange = (color) => setColor(color)

  return (
	<>
	  <HexColorPicker color={color} onChange={handleColorChange} />
	   <button onClick={() => setColor("#ffffff")}>Reset</button>
	</>
  )
}
export default Panel

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