Created
April 20, 2021 22:50
-
-
Save nrimsky/96d6e5ffc4a407b5f67dcd08fb1f9b1b to your computer and use it in GitHub Desktop.
App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import { GenericInput } from './TextEdit'; | |
const App = () => { | |
type myObj = { | |
name: string; | |
numLettersInName: number; | |
} | |
const [myNum, setNum] = useState(0); | |
const [myStr, setStr] = useState("Hello"); | |
const [complexObj, setComplexObj] = useState<myObj>({ name: "Kate", numLettersInName: 4 }); | |
useEffect(() => { | |
console.log(myNum); | |
console.log(myStr); | |
console.log(complexObj); | |
},[myNum, myStr, complexObj]); | |
return ( | |
<> | |
<GenericInput onChange={n => setNum(n)} dataToString={num => num.toString()} dataFromString={parseInt} value={myNum} /> | |
<GenericInput onChange={s => setStr(s)} dataToString={s => s} dataFromString={s => s} value={myStr} /> | |
<GenericInput onChange={o => setComplexObj(o)} dataToString={obj => obj.name} dataFromString={s => ({ name: s, numLettersInName: s.length })} value={complexObj} /> | |
</> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment