import { useState } from 'react';
const App = () => {
const [ color, setColor ] = useState('#fff');
const [ backgroundColor, setBackgroundColor ] = useState('#f44');
return (
<p style={{ 'color': color, 'backgroundColor': backgroundColor }} >
Hello world
</p>
);
};
export default App;
// You are actuallty better off using style props
// But you can do it, you have to double brace
// and camel-case the css properties
render() {
return (
<div style={{paddingTop: '2em'}}>
<p>Eh up, me duck!</p>
</div>
)
}
// use inline style in react
const myFunction = () => {
return (
<p style={{ fontSize: 24, margin: '0 auto', textAlign: 'center'}}>
Hello world
</p>
);
}
function MyComponent(){
2
3return <div style={{ color: 'blue', lineHeight : 10, padding: 20 }}> Inline Styled Component</div>
4
5}
return <div style={{display: 'inline-block'}}>
// Typical component with state-classes
<ul className="todo-list">
{this.state.items.map((item,i)=>({
<li
className={classnames({ 'todo-list__item': true, 'is-complete': item.complete })}>
{item.name}
</li>
})}
</ul>
// Using inline-styles for state
<li className='todo-list__item'
style={(item.complete) ? styles.complete : {}} />
inline css react