Can I pass props to a `components.Field`?

default discord avatar
allannnc
2 months ago
3

I want to pass

process.env.PAYLOAD_PUBLIC_NON_SENSITIVE_KEY

to a custom field component because

process.env === {}

on the admin panel.



I've tried to convert my collection file to

.tsx

but cannot pass an instantiated component directly



Anyone know if I can pass my own props to this component? Or some other way to access

process.env.PAYLOAD_PUBLIC_NON_SENSITIVE_KEY

?



Ended up just hardcoding the non-sensitive key as an

export const ...

instead of trying to use it through

process.env
  • discord user avatar
    seanzubrickas
    Payload Team
    last month

    Hey @allannnc apologies for not getting back to you sooner but we're glad you found a solution!

  • discord user avatar
    jarrod_not_jared
    Payload Team
    last month

    @allannnc you should be able to access envs prefixed with PAYLOAD_PUBLIC. Are you setting up dotenv in your payload config and server file?

  • default discord avatar
    allannnc
    last month

    Hey @jarrod_not_jared, my

    server.ts

    looks like



    import cookieParser from 'cookie-parser';
    import cors from 'cors';
    import dotenv from 'dotenv';
    import express from 'express';
    import payload from 'payload';
    
    dotenv.config();
    
    // ...internal imports
    // ...rest of file


    and my

    payload.config.ts

    looks very similar



    import path from 'path';
    
    // ...external lib imports e.g. from 'payload'
    
    dotenv.config();
    
    // ...internal imports
    
    // ...rest of file
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.