[英]javascript object field input value [object Object] instead of string Reactjs
i'm new here and i came across a doubt, i've created an input button where i can type my value, but unfortunatly it pass me only this value [object object]我是新来的,我遇到了一个疑问,我创建了一个输入按钮,我可以在其中输入我的值,但不幸的是它只传递了这个值 [object object]
That's my screenshot:这是我的截图:
My input function:我的输入 function:
function ButtonBID(props) {
return (
<div class="form__group field">
<input
value={props.text}
onChange={props.setText}
type="input"
class="form__field"
placeholder="Name"
name="bid"
id="name"
required
/>
<label for="name" class="form__label">
Bid now!
</label>
</div>
);
}
Where i define the function:我在哪里定义 function:
function RankingHome() {
const [textValue, setTextValue] = useState('');
return (
<>
<Navbar />
<HeroContainer>
<HeroBg>
<VideoBg
src={Video}
type="video/mp4"
autoPlay
loop
muted
playsInline
/>
</HeroBg>
<HeroContent>
<HeroItems>
<HeroH1>Who will win?</HeroH1>
<Table />
<div className="flexati">
<FirstPositionButton />
<ButtonBID text={textValue} setText={setTextValue} />
<Link to="/Pay">
<i class="far fa-check"></i>
</Link>
</div>
</HeroItems>
</HeroContent>
</HeroContainer>
</>
);
}
export default RankingHome;
as u can see i've created a const where i pass the value for text and setText, how could i resolve this issue?如您所见,我创建了一个常量,在其中传递了 text 和 setText 的值,我该如何解决这个问题? thanks!!谢谢!!
onChange
callback has event parameter from which you can get the changed text. onChange
回调具有事件参数,您可以从中获取更改的文本。
<input
value={props.text}
onChange={e => props.setText(e.target.value)}
...
/>
I see your error is you haven't received the data objects in the array我看到你的错误是你没有收到数组中的数据对象
you can to this你可以到这个
<input value={props.text} onChange={(e) => props.setText(e.target.value)}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.