【发布时间】:2020-02-06 01:02:07
【问题描述】:
我可以知道如何使用 React Admin 从 TextInput 字段中的 React Rrule Generator 获取 onChange() 值。
代码:
输出示例:
<RRuleGenerator
onChange={(recurrences) => console.log(`${recurrences}`)}
config={{
repeat: ['Monthly', 'Weekly'],
yearly: 'on the',
monthly: 'on',
end: ['Never', 'On date'],
weekStartsOnSunday: true,
hideError: true,
}}
/>
<TextInput label="Recurrences" source="recurrences" />
我使用的 react-rrule-generator:https://github.com/fafruch/react-rrule-generator
修改后的代码:
export const RACXICreate = (props) => {
const [state, setState] = useState('')
return (<Fragment>
<RRuleGenerator
onChange={(rrule) => setState({ rrule })}
value={state.rrule}
config={{
repeat: ['Monthly', 'Weekly'],
yearly: 'on the',
monthly: 'on',
end: ['Never', 'On date'],
weekStartsOnSunday: true,
hideError: true,
}}
/>
<TextInput label="Recurrences" source="recurrences" value={state.rrule} />
</Fragment>)}
但如果我使用这段代码,我就能得到值:
<input type="text" source="recurrences" label="Recurrences" value={state.rrule} />
但我最想得到 TextInput 字段中的值。
【问题讨论】:
标签: reactjs recurrence react-admin rrule