React · Senior · Question 64 of 75

How do you guarantee a module with secrets is never bundled into client code?

import "server-only";
export async function getSecretData() { /* uses API keys */ }

Explanation

'use server' marks Server Functions callable from the client - it does not hide a module. server-only is a build-time guard against accidental imports.

Further reading

Problem with a question

React · Senior · question 64

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz