I am looking to develop a versatile component in React that can be customized externally:
AnotherPlace.tsx
...
<BarComponent width={200}>
...
BarComponent.tsx
interface IBarProps {
//default width of 150px
width?: 150;
//default margin of 5px
margin?: 5;
}
interface IBarState{
checked: boolean;
}
class BarComponent extends Component<IBarProps, IBarState> {
constructor(props: IBarProps) {
super(props);
...
}
...
render(): ReactElement {
return (
<div className="bar-component"
data-width={this.props.width + 'px'}
>
...
BarComponent.scss
.bar-component {
...
width: attr(data-width length);
...
However, I keep encountering an error when running the application (chrome):
https://i.sstatic.net/oenLm.png
... It is essential for me to have a "number" as a property due to calculations needed for inner components so that everything functions seamlessly together.
EDIT:
Using "style" has not been effective for me as it interferes with the ::before ::after features in my scss which rely on modifying "right:" based on the width.
For a clearer picture, this is the foundation of my project: https://www.sitepoint.com/react-toggle-switch-reusable-component/