Declarative Programming
Example 1
[in App.js]
var isDone = true;
const strikeThrough = {textDecoration : "line-through"}
return <p style={isDone ? strikeThrough : null}>Buy Milk</p>
Imperative Programming
Example 1
[in index.js]
document.getElementById("root").style.textDecoration = "line-through";
Example 2
[in App.js]
function strike(){
document.getElementById("root").style.textDecoration="line-through";
}
function unstrike(){
document.getElementById("root").style.textDecoration=null;
}
function App() {
return(
<div>
<p>Buy Milk</p>
<button onClick={strike}>Change to strike through</button>
<button onClick={unstrike}>Undo</button>
</div>
) };
No comments:
Post a Comment