reactjs - 如何使用 React Admin 从 TextInput 字段中的 React Rrule Generator 获取 onChange() 值
问题描述
我可以知道如何使用 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 字段中获取值。
解决方案
const React, { useState, Fragment } from 'react'
const x = () => {
const [state, setState] = useEffect('')
return (
<Fragment>
<RRuleGenerator
onChange={val => setState(val)}
config={{
repeat: ['Monthly', 'Weekly'],
yearly: 'on the',
monthly: 'on',
end: ['Never', 'On date'],
weekStartsOnSunday: true,
hideError: true,
}}
/>
<TextInput label="Recurrences" source="recurrences" value={state} />
</Fragment>
)
}
使用这样的状态对象
推荐阅读
- switch-statement - ifelse 预期的声明或声明
- php - 我是否正确使用了 file_get_contents?
- ios - 当设置为“全部链接”时,DependencyService.Get 返回 null
- ios - 无法将正确的信息从 tableview 传递到新的视图控制器
- javascript - NodeJS - 找不到 JSON 文件
- c++ - 尽管没有错误,openCL 内核仍返回垃圾值
- python - 我需要一些帮助来尝试对字符串列表进行排序,但在该列表的特定索引处
- typescript - 在节点中使用 Typescript 正确解析 GraphQL 模块
- c++ - 使用堆栈为下一个最大数编写代码时面临 SIGSEGV(分段错误)
- java - getBean() 是否应该延迟 bean 实例化?