Basically, rather than having a hardcoded number in the code, we extract it from config with key 'tasks.itemsPerPage'. We utilize the useConfig hook for this purpose, that is imported from the @bluebase/core package.
Note that the useConfig hook has the same API as the useState hook in the react library.
Now that we are using the config, we also need to define its default value. Add the defaultConfigs object to your plugin as shown in the code below:
src/index.ts
import { createPlugin } from'@bluebase/core';exportdefaultcreatePlugin({ key:'tasks', name:'Tasks', description:'A todo app made with BlueBase framework.', defaultConfigs: {'tasks.itemsPerPage':10, }// ... other properties});
Now run your app and inspect. You will observe that BlueBase has successfully loaded the default config, which has been passed onto the GraphqlList component.
Step 1.3: Override Config Value
Now comes the fun part. Let's override this value from our app's configs:
configs.ts
exportconstconfigs= {'tasks.itemsPerPage':5,// ... other configs};
Run your app again. You will observe that the value in the configs was loaded and preferred over the defaultConfigs.
Now, let's see how we can allow the end-user to customize the value too.
Step 2.1: Create a Form
Let's create a form that will allow the user to input a value, and update the config when he presses the submit button.
For this purpose, we will use the JsonForm component from the @bluebase/plugin-json-schema-components.
The props of JsonForm component are very similar to the GraphqlJsonForm that we have previously usesd.
This is because the GraphqlJsonForm too uses JsonForm internally.
JsonForm component is built using the formik library.
Now we want to create a screen for "Tasks" in the Settings app. Luckily the Settings app allows this to be done via bluebase.plugin.setting-app.pages filter.
This filter inputs an array of screens in the settings app, all we have to do is to append our own screen configs and return the array. Create a new file and copy the following code: