new to React and working on existing project. I want when Select Elment changed (onInstrumentSelected called correctly), fill other fields of form with its related values, but not working. I could get correct data (checked in console.log) but could not not refill form by related new data.
const { Option, OptGroup } = Select;
const SettingsViewComponent: React.FC<{ base_instruments: any }> = props => {
let [settings, setSettings] = React.useState<ISettings>();
const instSearch = props.base_instruments;
let insId = 0;
React.useEffect(() => {
async function fetchsettings(ins) {
getSettings(ins)
.then(rsp => {
setSettings(rsp.data);
});
}
fetchsettings(insId)
}, [insId]);
const onInstrumentSelected = async (value, option) => {
insId = option.value;
const stt= await getSettings(option.value);
if (stt!= null) {
console.log(stt.data); //correct data here
// not working part:
settings = stt.data
setSettings(stt.data);
} else {
message.error('error');
}
};
return !settings ? (
<div />
) : (
<Form
initialValues={settings}
onFinish={onFinish}
onFinishFailed={onFinishFailed}>
<Form.Item label="instrument" name="instrumentId">
<Select onSelect={(val, op) => onInstrumentSelected(val, op)}>
{instOptions}
</Select>
</Form.Item>
<Form.Item label="Field 1" name="field1" >
<Input />
</Form.Item>
<Form.Item label="Field 2" name="field2" >
<Input />
</Form.Item>
<Form.Item label="Field3" name="field3">
<Input />
</Form.Item>
</Form>);};
export default SettingsViewComponent;