Skip to content

Instantly share code, notes, and snippets.

@marco-souza
Created December 2, 2019 19:23
Show Gist options
  • Save marco-souza/9751790128a302c57df9c310f82b6588 to your computer and use it in GitHub Desktop.
Save marco-souza/9751790128a302c57df9c310f82b6588 to your computer and use it in GitHub Desktop.
ink
react
ink
ink-text-input
typescript
@types/react
@types/node
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