How to apply style to element using property in React JS

1 Answer

0 votes
// counter.jsx

import React, { Component } from "react";

class Counter extends Component {
  state = {
    total: 895
  };

  style = {
      fontSize: 16
  }

  render() {
    return (
      <React.Fragment>
        <span style={ this.style } className="badge badge-primary m-2">
          Render Dynamically With bootstrap.css and Style Property: {this.getTotal()}
        </span>

      </React.Fragment>
    );
  }

  getTotal() {
    const { total } = this.state;
    return total === 0 ? "Zero" : total;
  }
}

export default Counter;
// index.js 

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css';
import Counter from './components/counter'


ReactDOM.render( 
  <Counter />,
  document.getElementById('root')
);

serviceWorker.unregister();


/*
run:
 
Render Dynamically With bootstrap.css and Style Property: 895
 
*/

 



answered Mar 31, 2020 by avibootz

Related questions

1 answer 250 views
1 answer 242 views
1 answer 208 views
1 answer 223 views
...