我的代碼從應用程序.js。這個想法是,當您在輸入中輸入文本時,屏幕應相應地更新。由于某種原因,設(shè)置狀態(tài)不起作用,我不知道為什么。import React, { Component } from 'react';import UserOutput from './Components/UserOutput';import UserInput from './Components/UserInput';class App extends Component { state = { username: 'Adib', }; changeUsername = (event) => { this.setState({ username: event.target.value, }); }; render() { return ( <div className="App"> <UserInput changed={this.changeUsername} /> <UserOutput name={this.state.username} /> </div> ); }}export default App;我的代碼來自用戶輸出.jsimport React from 'react';const userOutput = (props) => { return ( <div> <p>Username: {props.name}</p> <p>Hello {props.name}</p> </div> );};export default userOutput;我的代碼來自用戶輸入.jsimport React from 'react';const userInput = (props) => { return <input type="text" onChanged={props.changed} />;};export default userInput;
為什么我的文本在 React 中將文本寫入輸入標記時沒有更改
catspeake
2022-08-18 10:49:17