如何在页面上打印"hello name"?

  • 本文关键字:hello name 打印 reactjs
  • 更新时间 :
  • 英文 :


我应该打印在页面上"你好名字"如果年龄在十八岁或以上。否则,页面打印";你太年轻了;。现在页面只打印";你太年轻了;。

function HelloName() {
const [name, setName] = React.useState({name: ''});   
const [age, setAge] = React.useState({age: ''});

const inputChanged = (event) => {
setName({...name, [event.target.name]:
event.target.value}) 

}
const formSubmitted = (event) => {
event.preventDefault();
if (age >= 18) {
alert("Hello " + name); }
else {
alert("You are too young"); }
}

年龄被声明为对象。年龄是了解您年龄的正确方式。

年龄也被声明为字符串。如果你要使用TS,如果你将Int分配给字符串,它会给你错误

相关内容

最新更新