如何使用React Admin从TextInput字段的React Rrule Generator中获取onChange()值

问题描述 投票:0回答:1

也许我知道如何使用React Admin从TextInput字段中的React Rrule Generator中获取onChange()值。

代码:

The code

输出示例:

The output example

用户选择时返回的“递归”值:The "recurrences" value returned when the user chosen

<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

reactjs recurrence react-admin rrule
1个回答
0
投票

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>
    )
  }

使用这样的状态对象

© www.soinside.com 2019 - 2024. All rights reserved.