我正在使用 jsDoc 來解釋 onChange 函式,所以我的任務是,如果有人想使用我添加到我的倉庫中的組件,我想告訴用戶 onChange 就像它接受的引數一樣,所以我很困惑,如果我添加一些解釋,那么一些另一個能夠理解或不理解
This is my component
/**
* @type {string}
* @param {*} onChange - onChange will accept parameter as (value: any) => void.
* @returns
*/
我需要解釋的這個 onchange 函式意味著如果有人使用我的組件,那么用戶需要像這樣傳遞引數,我的組件 onChnage 接受這樣的輸入
const handleDateChange = (date) => {
setSelectedDate(date);
};
<DatePicker
disableToolbar
variant="inline"
format="MM/dd/yyyy"
margin="normal"
id="date-picker-inline"
label="Date picker inline"
value={selectedDate}
onChange={handleDateChange}
KeyboardButtonProps={{
'aria-label': 'change date',
}}
/>
uj5u.com熱心網友回復:
如果我理解正確,您想記錄以下用于onChangeReact 組件處理程式的函式簽名:
const handleDateChange = (date) => {
setSelectedDate(date);
};
它似乎是一個消耗date引數的函式,我假設該引數是此答案的字串。以下是我將如何記錄函式簽名。
@param {(date: string) => void} onChange - date change handler.
更新
啊,我剛剛意識到您想要記錄 React 組件的道具。先定義props物件,再定義props.onChange。
/**
* DatePicker component
* @param {Object} props - component props
* @param {(date: string) => void} props.onChange - date change handler.
* @returns JSX.Element
*/
export default function DatePicker({
...props
}) {
...
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardDatePicker {...props} />
</MuiPickersUtilsProvider>
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338466.html
標籤:javascript 反应 jsdoc
