I'm new to React, just to get the idea, how would you convert this snippet to React?
<div id="input" contenteditable></div>
<button id="submit">Convert to kg!</button>
<br>
<div id="output"></div>
<script>
const button = document.querySelector('#submit');
const input = document.querySelector('#input');
function convert() {
let x=input.textContent;
if (isNaN(x))
{
alert("Must input numbers");
return false;
} else {
const pounds = document.querySelector('#input').textContent;
let kg = pounds*0.45;
document.querySelector('#output').innerHTML = pounds + " pounds is " + kg + " kg";
}
}
button.addEventListener('click', convert);
</script>
I transformed html to jsx
<div
id="input"
contentEditable
style={{ width: "40%", border: "solid 1px black", margin: "20px}" }}
/>
<button id="submit">Convert to kg!</button>
<br />
<div id="output" style={{ marginTop: 20 }} />
</div>
But, how to go about Javascript, no idea... Can someone give a direction maybe?