conditionally hide icon button
Hi , I have a component as follows import * as React from 'react'; import { TextField, ITextFieldProps } from "office-ui-fabric-react/lib/TextField"; import { IconButton } from "office-ui-fabric-react/lib/Button"; export interface ITextFieldWithEditProps { value: string; onValueChanged?: (oldValue, newValue) => void; dangerouslySetInnerHTML?:boolean; } export class TextFieldWithEdit extends React.Component<ITectFieldWithEditProps, {}>{
public render() {
let textFieldProps: ITextFieldProps = { value: this.props.value };
debugger;
return (
<div>
<div dangerouslySetInnerHTML={{ __html: this.props.value }} />
<IconButton iconProps={{iconName:"Edit"}} hidden={(this.props.onValueChanged===undefined)} />
</div>
);
}
}
I want to hide the icon button if the caller did not pass in a value for the onValueChanged property. the code above does not work, How can I conditionally hode an IconButton? doesnt seem to be a hidden prop.
You can hide it using conditional rendering:
{this.props.onValueChanged && <IconButton iconProps={{iconName:"Edit"}} />}
this is definitely the proper solution. don't render the icon if your check if false. closing this up.