Hey
@1357879907392164101
Check out the custom components example here:
https://github.com/payloadcms/payload/tree/main/examples/custom-componentsAlso have a look at the docs here:
https://payloadcms.com/docs/custom-components/overviewthanks
My pleasure
'use client'
import type { ArrayFieldClientComponent } from 'payload'
import { ArrayField } from '@payloadcms/ui'
import React from 'react'
export const CustomArrayFieldClient: ArrayFieldClientComponent = (props) => {
return <ArrayField {...props} />
}Where can I put my custom value here? Since Forexample i will use like fetching and stuff
If you want to pass a custom prop to your component you can adjust your types like so:
'use client'
import type { ArrayFieldClientProps} from 'payload'
import { ArrayField } from '@payloadcms/ui'
import React from 'react'
type Props = { /** Your custom types here */ } & ArrayFieldClientProps
export const CustomArrayFieldClient: React.FC<Props> = (props) => {
return <ArrayField {...props} />
}oh. Nice. I meant like I want to put on data. Like i fetch calculated then display on the Field.
You fetch some data like you typically would, then you use either
useFieldor another React hook as shown here:
https://payloadcms.com/docs/admin/react-hookslike I have to use customField not ArrayField right?
No, you can use ArrayFields
oh. I see. u change the value using hooks right?
Right
oh ok. Thanks.
My pleasure
if i use payload delete on media collection will it also trigger the deletion inside my s3?
Yep
Thanks
On this example U can create both client and server component right? What is the purpose of creating both
Server components get special props passed to them like a
reqwhich has a Payload instance and a user object on it. You can use RSC's to communicate with your server directly as its still on the server, but it cannot have any interactions. Client components can have interactions but cannot use server-only functions or actions. I'd encourage you to look further into React and the differences between a client and server component for more info
As this is mostly a React concept, it's jsut that Paylaod will pass different default props to your component depending on the context they run in
oh ok. If I use some componenet like useEffect then I should use client componenet right? And then calling rest api to the server. since payload.find or something only exist on server?
am i right?
One pattern, for example, is to wrap a client component with a server component such that you do your initial data fetching on the server component and then pass props down to your client component for interaction.
Yes, you're right
You can call REST api's in both
Via fetch
I know but I can't call payload.find on client?
Right, you can't use the Local API on the client
Thank you
Star
Discord
online
Get dedicated engineering support directly from the Payload team.