Created
June 10, 2021 21:07
-
-
Save gitumarkk/28e03d725ef6c343e4aba74622318993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import PropTypes from 'prop-types'; | |
export default class MyCustomComponent extends Component { | |
render() { | |
const {id, label, setProps, value} = this.props; | |
return ( | |
<div id={id}> | |
ExampleComponent: {label} | |
<input | |
value={value} | |
onChange={ | |
/* | |
* Send the new value to the parent component. | |
* setProps is a prop that is automatically supplied | |
* by dash's front-end ("dash-renderer"). | |
* In a Dash app, this will update the component's | |
* props and send the data back to the Python Dash | |
* app server if a callback uses the modified prop as | |
* Input or State. | |
*/ | |
e => setProps({ value: e.target.value }) | |
} | |
/> | |
</div> | |
); | |
} | |
} | |
MyCustomComponent.defaultProps = {}; | |
MyCustomComponent.propTypes = { | |
/** | |
* The ID used to identify this component in Dash callbacks. | |
*/ | |
id: PropTypes.string, | |
/** | |
* A label that will be printed when this component is rendered. | |
*/ | |
label: PropTypes.string.isRequired, | |
/** | |
* The value displayed in the input. | |
*/ | |
value: PropTypes.string, | |
/** | |
* Dash-assigned callback that should be called to report property changes | |
* to Dash, to make them available for callbacks. | |
*/ | |
setProps: PropTypes.func | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment