我有了自己的类组件和state,我不想这样使用:

const [selectedDay, setSelectedDay] = useState(null);

然后,我应该如何使用?

发布于 2020-10-11 22:21
共1个回答
XL
游客xlRpUN

直接上代码:


import React from "react"; import ReactDOM from "react-dom"; import 'react-persian-calendar-date-picker/lib/DatePicker.css'; import DatePicker from 'react-persian-calendar-date-picker'; import "./styles.css"; class App extends React.Component { state = { selectedDay: null } handleDatePickerChange = newValue => { this.setState({ selectedDay: newValue }); } render() { return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Start editing to see some magic happen!</h2> <DatePicker selectedDay={this.state.selectedDay} onChange={this.handleDatePickerChange} inputPlaceholder="انتخاب روز" /> </div> ); } } const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement);

image.png

参见:https://codesandbox.io/s/jovial-moore-h186k?file=/src/index.js

回答问题