-
-
Save marco-souza/9751790128a302c57df9c310f82b6588 to your computer and use it in GitHub Desktop.
ink
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
react | |
ink | |
ink-text-input | |
typescript | |
@types/react | |
@types/node |
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 } from 'react' | |
import { Text, Box, Static } from 'ink' | |
import TextInput from 'ink-text-input'; | |
export default () => { | |
const [message, setMessage] = useState<string>('') | |
const [messageList, setMessageList] = useState<Array<string>>([]) | |
const handleSubmit = (value: string) => { | |
value && setMessageList([ | |
...messageList, | |
value, | |
]) | |
value && setMessage('') | |
} | |
return ( | |
<> | |
<Box width='100vw'> | |
<Box height={3}> | |
<Static> | |
{messageList | |
.map((item, index) => ( | |
<Box width='100vw' key={item + index}> | |
<Text bold>Message {index}:</Text> | |
<Text> {item}</Text> | |
</Box> | |
))} | |
</Static> | |
</Box> | |
<Box height={1} padding={2}> | |
<TextInput | |
placeholder='enter your msg here' | |
value={message} | |
onChange={setMessage} | |
onSubmit={handleSubmit} | |
/> | |
</Box> | |
</Box> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment