I have tried const DataList = () => { at the beginning and ending but it wasn't working
Add export default to this code because it shows an error in my app component
import { render } from '@testing-library/react'
import React,{useState} from 'react'
import ReactDOM from 'react-dom/client';
const Thingy = ({...props}) => {
const [userInput, setUserInput] = useState('');
const [showResult, setShowResult] = useState(false);
const handleChange = ev => (setUserInput(ev.target.value), setShowResult(false));
const convertChar = ch => {
const c = ch.toLowerCase();
if ('0' <= c && c <= '9') return ch.toString();
if (!('a' <= c && c <= 'z')) return ch;
return c.charCodeAt(0) - 'a'.charCodeAt(0) + 1;
};
const transformInput = () => userInput
.split('') letters
.map(c => convertChar(c))
.join(' ');
getResult = () => userInput
.split('')
.map(c => convertChar(c))
.filter(
c => (
typeof c !== 'string' &&
!isNaN(c)
)
)
.reduce(
(total, itm) => total + itm, 0
);
return (
<div>
<div>
<label htmlFor={'usrinp'}>Enter text: </label>
<input
id="usrinp"
value={userInput}
onChange={handleChange}
/>
</div>
{
userInput.length > 0 &&
<p>Converted text to: {transformInput()}</p>
}
<button onClick={() => setShowResult(true)}>
Submit
</button>
{
showResult && <p>Result is: {getResult()}</p>
}
</div>
);
};
ReactDOM.render(
<div>
<h4>Transform User input text to numbers</h4>
<Thingy />
</div>,
document.getElementById("rd")
);