This document details the current behavior of default values in components
within the Admin and introduces a new feature that allows developers to specify
default props directly within function parameters. This enhancement improves
user experience by ensuring that default values are reflected correctly in both
the Admin interface and the rendered components.
In the current setup, default values for props are hardcoded within the
component’s code. This leads to a mismatch between the Admin interface and the
rendered component:
Admin: When a component has default values set in its code, the form in
the Admin interface displays empty fields instead of these default values.
Rendered Component: Despite the empty form fields, the component still
renders with the hardcoded default values.
JSON: The JSON file displayed to the developer in the Admin interface
doesn’t include these default values, leading to confusion and a poor user
experience.
Consider the following scenario: A footer component has default props defined in
its code. In the Admin interface, the form fields for these props are empty, but
the component is rendered with the hardcoded values. This disconnect makes it
difficult for developers and content managers to map input text to the page data
accurately.
To address this issue, the Admin now supports specifying default props directly
within the function parameters of any block. This ensures that default values
are consistently reflected in the interface, the rendered component, and the
JSON file shown to developers, leading to benefits like:
Consistency: Default values are visible and editable in the admin
interface, ensuring a consistent user experience.
Clarity: Developers can see the actual default values in the JSON file,
reducing confusion.
Simplicity: Easier to manage and update default values directly within the
function parameters.
This feature supports simpler scenarios, covering basic data types and nested
objects.
By specifying default props directly in the function parameters, this new
feature improves the integration between the admin interface and the component
rendering. This change simplifies the workflow for developers and enhances the
overall user experience by ensuring that default values are visible and
manageable across all parts of the Admin.