Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting dash's(plotly) react functional component into class component

I just learned about the dash's Create your own components . I'm also new in react. I generally prefer to write component in react in class. I created a react file where I dumped the source code of dash html component . The Div component is written in function. I want to convert this Div component into class. Here what i am doing -

import React from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';

class Div extends Component{

   render(){
     const props = this.props;
     const dataAttributes = {};
     if(props.loading_state && props.loading_state.is_loading) {
          dataAttributes['data-dash-is-loading'] = true;
     }

     return (
        <div id = "scroll-div" className="scroll-bar"
            onClick={() => props.setProps({
                n_clicks: props.n_clicks + 1,
                n_clicks_timestamp: Date.now()
            })}
           {...omit(['n_clicks', 'n_clicks_timestamp', 'loading_state', 'setProps'], props)}
        {...dataAttributes}
        >
           {props.children}

        </div>
    );
  }
};
Div.defaultProps = {
  n_clicks: 0,
  n_clicks_timestamp: -1,
};

Div.propTypes = {
     .......
};

export default Div;

But this conversion that i made into class is not working. What am I doing wrong? What will be the correct converion of the Div component into class?

Thanks :)

like image 820
Akhil Mittal Avatar asked Oct 27 '25 09:10

Akhil Mittal


1 Answers

You should import :-

import React,{Component} from 'react';

Or in the you can modify your class declaration as :-

class Div extends React.Component{}
like image 65
Aayush Vijay Avatar answered Oct 28 '25 23:10

Aayush Vijay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!