In react-admin I want alter the form before submit, add variable from state. But value of variable is remain initial and I can't set it to actual. There is a code snippet below. How can I achieve my goal?
const MyComponent = props => { // setSomeVariable will be called elsewhere, so the value of someVariable will be changed const [someVariable, setSomeVariable] = useState('initial') const transform = data => { data['someVariable'] = someVariable //it's value will remain 'initial'. How to set actual value? return data } return <Create {...props} transform={transform}> ... </Create> }
Similar behavior was in these questions, but they were not answered:
Trying to use react-admin transform function on <Create />
React Admin: how to pass state to transform
Thanks.
https://stackoverflow.com/questions/66953311/why-we-cant-get-state-in-the-transform-function April 05, 2021 at 08:48PM
没有评论:
发表评论