Reputation: 865
i am very new to react and do not know how to introduce the following condition into a property. I'm using a component of ui material and I want to introduce the condition that if "error= true" it should be set to "disabled=false"
return (
<MuiTextField
value={value}
disabled={disabled}
error={error}
fullWidth={fullWidth}
label={<span className={classesLabel.inner}>{label}</span>}
helperText={helperText}
onChange={handleChange}
classes={{
root: classes.root,
}}
{...props}
/>
);
}
what I would like to do is to introduce at the point of the error attribute a condition similar to this
error={error,{if (error) { disabled = false}}}
I know the syntax is not correct but it is a way of explaining what I want to do
Someone to give me an idea of how to introduce this condition? Many
Upvotes: 0
Views: 31
Reputation: 5054
You can do the following,
const MUITextDisabledProps = { disabled: false};
return (
<MuiTextField
value={value}
disabled={disabled}
error={error}
{error && ...MUITextDisabledProps}
... other props
/>
);
Upvotes: 1