Skip to content

Instantly share code, notes, and snippets.

@micahgodbolt
Last active April 3, 2018 22:51
Show Gist options
  • Save micahgodbolt/86c19fe870ff477af7fe0432c500dcac to your computer and use it in GitHub Desktop.
Save micahgodbolt/86c19fe870ff477af7fe0432c500dcac to your computer and use it in GitHub Desktop.
class Content extends React.Component {
constructor() {
super();
}
render() {
return (
<Fabric className='foo'>
<DefaultButton
onClick= {() => alert('hello')}
onRenderText= {this._onRenderText}
text="Hi There"
foo="Foo"
/>
</Fabric>
);
}
private _onRenderText:IButtonProps['onRenderText'] = (props, defaultRender) => {
return (
<span> {defaultRender()} {props.foo} </span>
);
}
}
class Content extends React.Component {
constructor() {
super();
}
render() {
return (
<Fabric className='foo'>
<DefaultButton
onClick= {() => alert('hello')}
onRenderText= {this._onRenderText}
text="Hi There"
foo="Foo"
/>
</Fabric>
);
}
private _onRenderText:IRenderFunction<IButtonProps> = (props, defaultRender) => {
return (
<span> {defaultRender()} {props.foo} </span>
);
}
}
@nickytonline
Copy link

From https://twitter.com/nickytonline/status/981301072697360390

I'm sure there's more to your class, but if it's something simple like this, it could just be a React.SFC<IButtonProps> and _onRenderText could be a utility function since it does not use this.

// import IButtonProps and IRenderFunction

class Content extends React.Component<IButtonProps, {}> {  
  render() {
    return (
      <Fabric className='foo'>
        <DefaultButton
          onClick= {() => alert('hello')}
          onRenderText= {this._onRenderText}
          text="Hi There"
          foo="Foo"
        />
      </Fabric>
    );
  }
       
  private _onRenderText:IRenderFunction<IButtonProps> = (props, defaultRender) => {
    return (
      <span> {defaultRender()} {props.foo} </span>
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment