English 中文(简体)
2. 反应输入色体
原标题:React input color picker

我不理解,投入的彩色类型是如何运作的。

我试图带一个色体,把这个数值变成一个国家变量“col”。

const [color, setColor] = useState(false);
const colorPicker = () => {
    console.log("colorPicker", color.target);
    return(
        <input type="color" value={color} onChange={setColor}/>
    );
}

但是,这只给我留下了青.和我试图看像肤色那样的 j子。 目标是:

Warning: This synthetic event is reused for performance reasons. If you re seeing this, you re accessing the property target on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https:// fb dot me/react-event-pooling for more information.

最佳回答

<代码>onChange 活动发送人收到作为参数的物体。

该活动标有选定颜色作为<代码>event.target. Value,就像固定案文输入一样。


With this in mind, the following will allow you to hold on to the selected color:

const ColorPicker = () => {
  const [color, setColor] = useState(null);

  console.log("colorPicker", color);

  return (
    <input type="color" value={color} onChange={e => setColor(e.target.value)} />
  );
}

关于你试图查阅<代码>event.target时发现的错误,错误信息已经做了很好的解释。 我建议你看一下它所提到的文件页,这应该有助于你理解这个问题。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签