Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

How to define SCSS type attribute with REACT property

$
0
0

Basically I want to create a reusable component which can be slightly modified from the outside in react:

SomewhereElse.tsx

...<FooComponent width={200}>...

FooComponent.tsx

interface IFooProps {  //default width of 150px  width?: 150;  //default margin of 5px  margin?: 5;}interface IFooState{  checked: boolean;}class FooComponent extends Component<IFooProps, IFooState> {    constructor(props: IFooProps) {        super(props);        ...    }...    render(): ReactElement {        return (<div className="foo-component"              data-width={this.props.width +'px'}>          ...

FooComponent.scss

.foo-component {    ...    width: attr(data-width length);    ...

But it always gives me the following error when running the application (chrome):

errorinchrome

... Please consider that I need a "number" as property because I am doing some calculations based on that number for some of the inner components so everything fits together.

EDIT:

Using "style" is not working for me because I have some ::before ::after features in my scss which are broken when using style because they occasionally modify "right:" based on the width.

For better understanding, this is my base:https://www.sitepoint.com/react-toggle-switch-reusable-component/


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>