Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
allannnclast year
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
    last year

    Hey

    @946299884070375424

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

  • @946299884070375424

    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
    allannnclast year

    Hey

    @281120856527077378

    , 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
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.