I'm fairly new to React-Admin. I've got a really difficult time to grasp the basic features of the parent/children relation and how to interact with props/parameters/attributes that can be passed between the two.
Namely, I'm trying to understand how I can read/access attributes that a parent sent to its child from inside the child. It may seems fairly simple but I cannot understand how to do it.
To explain furthermore my question, I'll get to my example :
<ReferenceInput
source="id"
reference="anotherPageList"
>
<SelectInput
optionText="name"
validate={required()}
initialValue={MyCustomFunction(this.choices)}
/>
</ReferenceInput>
It says in the React-admin doc of the ReferenceInput component : "This component fetches the possible values in the reference resource(using dataProvider.getList()), then delegates rendering to a subcomponent, to which it passes the possible choices as the choices attribute."
So I was hoping I could use the attribute "choices" in MyCustomFunction in my SelectInput, since it's passed from the parent. But I am not capable in ever accessing this attribute "choices".
I'm aware that in my case, this attribute is still used by the SelectInput to fill its own "choices" attributes, and this works fine, but I would like to understand how I can access it myself.
i was able to successfully interact with the props sent from the ReferenceInput to the SelectInput by adding a custom component in between :
const CustomComponent = (props) => {
return (
<SelectInput {...props}
optionText="name"
validate={required()}
initialValue={MyCustomFunction(props.choices)}
/>
);
};
<ReferenceInput
source="id"
reference="anotherPageList"
>
<CustomComponent />
</ReferenceInput>