What's the difference between siblingData and data? #2385
-
As I observe they are the same. In what situation they will differ? Here's the answer from chatgpt(not really helping)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @Stupidism, Good question! Suppose you are working on a field hook that needs to use field data in a nested structure that repeats, like the array or blocks fields. If you had to do this with only the It sounds like this is an opportunity to improve our docs. Here is a simplified example of a collection config where this is apparent: const fields = [
{
type: 'array',
name: 'top',
hooks: {
afterRead: [
({ data, siblingData }) => {
// data and siblingData are the same at the top, so this one doesn't help
},
],
},
fields: [
{
name: 'nested',
type: 'group',
fields: [
{
name: 'field',
type: 'text',
hooks: {
afterRead: [
({ data, siblingData }) => {
// siblingData.siblingOfField is now very easy to access
},
],
},
},
{
name: 'siblingOfField',
type: 'text',
},
],
},
],
},
] |
Beta Was this translation helpful? Give feedback.
Hi @Stupidism, Good question!
Suppose you are working on a field hook that needs to use field data in a nested structure that repeats, like the array or blocks fields. If you had to do this with only the
data
at the top of the document you would have a terrible time traversing from the top to the correct index and nested field.It sounds like this is an opportunity to improve our docs.
Here is a simplified example of a collection config where this is apparent: