Reputation: 11645
I try to create a reference to a React-Admin element using the useRef hook, but I do not succeed.
Same doing with native react.js works fine using a simple <input>
field, but with a react-admin component the reference is null.
Anyone knows how to reference an element in react-admin ?
const myForm = (props) => {
const refContainer = useRef(null);
const myClick = () => {
console.log('clicked !', refContainer); // refContainer is null !!!
refContainer.current.value = '1';
};
return <Edit {...props}>
<SimpleForm>
<TextInput source='myValue' ref={refContainer} value='0'/>
<input type="button" value="change" onClick={myClick}/></SimpleForm>
</Edit>;
};
Upvotes: 0
Views: 1098
Reputation: 3319
Try to use instead ref: inputRef
https://material-ui.com/ru/api/input/
<TextField inputRef={refContainer} />
Upvotes: 1