Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Class component covert to function component

Problem is static variable.

class component use static variable like this.

// component.js
<ProgressWindow messageSet={ProgressWindow.MESSAGE_FOR_REPORT} />
 
// ProgressWindow.js
class ProgressWindow extends React.Component {
  static  MESSAGE_FOR_REPORT = 'report';
  static MESSAGE_FOR_SETTING = 'setting';
}

My mission is that static variable’s convert to function component.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I need get messageSet value in new function ProgressWindow component.

How can i?

>Solution :

try this

const ProgressWindow = (props) => {
    return (
        <div>{props.MESSAGE_FOR_REPORT}</div>
    );
};

ProgressWindow.MESSAGE_FOR_REPORT = 'report';
ProgressWindow.MESSAGE_FOR_SETTING = 'setting';

export default ProgressWindow;

There is alternative static variable in Functional Component

ProgressWindow.MESSAGE_FOR_REPORT = 'report';
ProgressWindow.MESSAGE_FOR_SETTING = 'setting';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading