You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Webpages commonly need to conditionally render content only if a content field has a value. For example, you may only want to render an <h1> element if a Title field has a value.
This can currently be accomplished with @prismicio/client's isFilled set of helpers:
Although the above code is not more concise than the isFilled.richText() version (it is actually more characters), it is easier to read and edit. The React syntax fits in with the surrounding code better than the ternarry and isFilled helper.
This solution can be ported to other integration libraries, like @prismicio/vue and @prismicio/svelte.
Type Narrowing
isFilled narrows the type of the provided field. After narrowing the field, you can be sure that the field is filled, and you will get autocompletion that suggests that.
When using JSX, you will not get that effect because TypeScript doesn't support type predicates in JSX (see Using type predicates).
To get around that limitation, we may need to introduce a dedicated render prop (render={(field) => {...}}) or render prop via children (i.e. (field) => {...}) rather than supporting children directly.
Either case may not work in Server Components since it passes a function.
Describe alternatives you've considered
isFilled helpers, as described above.
Pre-process query results to bake metadata into values. For example, a key text field could have a hidden _hasValue computed property that tells us if it is filled. Pre-processing content requires access to the type JSON definitions, which is not available on the client.
Build-time generated that creates isFilled helpers specific for your content. It's not clear exactly what this is yet.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Webpages commonly need to conditionally render content only if a content field has a value. For example, you may only want to render an
<h1>
element if a Title field has a value.This can currently be accomplished with
@prismicio/client
'sisFilled
set of helpers:While the above code works, it is verbose and feels procedural.
Describe the solution you'd like
A dedicated React component that accomplishes the same as above in a declarative way would be an improvement.
Although the above code is not more concise than the
isFilled.richText()
version (it is actually more characters), it is easier to read and edit. The React syntax fits in with the surrounding code better than the ternarry andisFilled
helper.This solution can be ported to other integration libraries, like
@prismicio/vue
and@prismicio/svelte
.Type Narrowing
isFilled
narrows the type of the provided field. After narrowing the field, you can be sure that the field is filled, and you will get autocompletion that suggests that.When using JSX, you will not get that effect because TypeScript doesn't support type predicates in JSX (see Using type predicates).
To get around that limitation, we may need to introduce a dedicated
render
prop (render={(field) => {...}}
) or render prop viachildren
(i.e.(field) => {...}
) rather than supportingchildren
directly.Or...
Either case may not work in Server Components since it passes a function.
Describe alternatives you've considered
isFilled
helpers, as described above._hasValue
computed property that tells us if it is filled. Pre-processing content requires access to the type JSON definitions, which is not available on the client.isFilled
helpers specific for your content. It's not clear exactly what this is yet.Additional context
N/A
The text was updated successfully, but these errors were encountered: