reactjs - React Add Css to Component without addon library -
i have created react component. in case component called header.js.
here code:
import react "react"; export class header extends react.component { render() { return ( <div> <h1>header component</h1> </div> ); } }
what need add css same component file inside js.
i need without using addon libraries jss etc.
how can this?
you can apply css
following ways:
1. directly html
element:
import react "react"; export class header extends react.component { render() { return ( <div style={{fontsize: '10px'}}> <h1>header component</h1> </div> ); } }
2. can define css object
in starting of file use object
in style attribute:
let style = { a: {fontsize: '10px'} }; import react "react"; export class header extends react.component { render() { return ( <div style={style.a}> <h1>header component</h1> </div> ); } }
note: 2nd way better way, because maintain code, makes code clean, compact, more readable , maintainable.
Comments
Post a Comment