From 8ef1b09fefd05f2c86205f81911e5be8d6bd18a7 Mon Sep 17 00:00:00 2001 From: Pranav Yadav Date: Sat, 4 Mar 2023 01:05:06 +0530 Subject: [PATCH] React Module Conventions RFC v3 --- text/0000-server-module-conventions.md | 136 +++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 text/0000-server-module-conventions.md diff --git a/text/0000-server-module-conventions.md b/text/0000-server-module-conventions.md new file mode 100644 index 00000000..bbdb0b4d --- /dev/null +++ b/text/0000-server-module-conventions.md @@ -0,0 +1,136 @@ +- Start Date: 2023-02-04 +- RFC PR: (leave this empty) +- React Issue: (leave this empty) +- Author: Pranav Yadav [@Pranav-yadav](https://github.com/Pranav-yadav) + +# Summary + +Better conventions for Server/Client Components, as an revision to [the v2](https://github.com/reactjs/rfcs/pull/227) of [the original proposal v1](https://github.com/reactjs/rfcs/pull/189) + +Note: The v1 and v2 terms used throughout this RFC refer to the above hyperlinked RFCs only. + +# Changes Since v2 + +- using `"use csr"` instead of `"use client"` i.e. replacing `client` with `csr` +- similarly, reserve `"use ssr"` for future use with Server only. + +# Basic example + + + +To mark a component as a Client Component, add `'use csr'` directive at the top of your file. This lets you use features like state and event handlers: + +```js +'use csr'; + +import { useState } from 'react'; + +function Button({ children, onClick }) { + // ... +} +``` + +Diff - current syntax and conventions: +```diff ++'use csr'; +-'use client'; + +import { useState } from 'react'; + +function Button({ children, onClick }) { + // ... +} +``` + +## `"use csr"` Directive + +```js +// Parent.js +import Component from "./Component.js"; +function Parent() { + // Component is of type Reference where T is the type + // of the default export of Component.js + // Because of this React knows that it can't render it on + // the server and instead will leave it as a placeholder + // to later be rendered on the client. + return ; +} +``` + +```js +// Component.js +"use csr"; + +function Component() { + let [state, setState] = useState(false); + return setState(true)} value={state} />; +} +``` + +# Motivation + + + + + +# Detailed design + + + + + +# Drawbacks + + + + + +# Alternatives + + + + + +# Adoption strategy + + +# How we teach this + + + + +# Unresolved questions + + +