Update text with a button
Build a block where a button updates displayed text.
Before you start
Add the component
import { createComponent, createIntegration } from '@gitbook/runtime';
const textUpdater = createComponent({
componentId: 'text-updater',
initialState: () => ({
message: 'Select the button to update this text.'
}),
async action(element, action) {
if (action.action !== 'update-message') {
return {};
}
return {
state: {
message: 'The button updated this text.'
}
};
},
async render(element) {
return (
<block>
<text>{element.state.message}</text>
<button
label="Update text"
onPress={{
action: 'update-message'
}}
/>
</block>
);
}
});
export default createIntegration({
components: [textUpdater]
});Add the block to your manifest
Test the block
Continue building
Last updated
Was this helpful?