Create an interactive text input
Build a block that stores text and shows it after a button action.
Before you start
Add the component
import { createComponent, createIntegration } from '@gitbook/runtime';
const interactiveTextInput = createComponent({
componentId: 'interactive-text-input',
initialState: () => ({
message: 'Enter a message, then select Update text.'
}),
action: async (element, action) => {
if (action.action !== 'show-text') {
return {};
}
return {
state: {
message: element.state.content ?? ''
}
};
},
render: async (element) => (
<block>
<textinput
state="content"
label="Message"
placeholder="Enter a message"
/>
<button
label="Update text"
onPress={{ action: 'show-text' }}
/>
<text>{element.state.message}</text>
</block>
)
});
export default createIntegration({
components: [interactiveTextInput]
});Add the block to your manifest
Test the block
Next steps
Last updated
Was this helpful?