Skip to content

Instantly share code, notes, and snippets.

@wickstjo
Created August 7, 2019 07:01
Show Gist options
  • Save wickstjo/c01d7e32a263e91124d9be2bb5c5138b to your computer and use it in GitHub Desktop.
Save wickstjo/c01d7e32a263e91124d9be2bb5c5138b to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
import { render } from 'ink';
import Input from './components/input';
function Container() {
// LOCAL STATE
const [local, set_local] = useState({
name: 'testing'
})
// UPDATE FIELD
function update({ property, value }) {
set_local({
...local,
[property]: value
})
}
return (
<Input
header={ 'Enter your query' }
value={ local.name }
placeholder={ 'something' }
dispatch={ update }
id={ 'name' }
/>
)
}
render(<Container />)
import React, { Fragment } from 'react';
import { Box } from 'ink';
import TextInput from 'ink-select-input';
function Input({ header, value, placeholder, dispatch, id }) { return (
<Fragment>
<Box marginRight={ 1 }>{ header }:</Box>
<TextInput
value={ value }
placeholder={ placeholder }
onChange={
query => dispatch({
property: id,
value: query
})
}
/>
</Fragment>
)}
export default Input;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment