Skip to content

Commit

Permalink
Merge pull request #2062 from reduxjs/pr/exports-rsc
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Aug 26, 2023
2 parents acb455c + 58296db commit bec3fa7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"./package.json": "./package.json",
".": {
"types": "./dist/react-redux.d.ts",
"react-server": "./dist/rsc.mjs",
"import": "./dist/react-redux.mjs",
"default": "./dist/cjs/index.js"
},
Expand Down
34 changes: 34 additions & 0 deletions src/index-rsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type * as normal from './index'
import type * as rsc from './index-rsc'

// checks to make sure we didn't forgot to replicate any exports

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _check: typeof normal = {} as typeof rsc
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _check2: typeof rsc = {} as typeof normal

// -------------------------------------------------------------------------------------

function throwNotSupportedError(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
...args: any[]
): any {
throw new Error(
'This function is not supported in React Server Components. Please only use this export in a Client Component.'
)
}

export {
throwNotSupportedError as batch,
throwNotSupportedError as Provider,
throwNotSupportedError as connect,
throwNotSupportedError as useSelector,
throwNotSupportedError as useDispatch,
throwNotSupportedError as useStore,
throwNotSupportedError as createDispatchHook,
throwNotSupportedError as createSelectorHook,
throwNotSupportedError as createStoreHook,
}
export const ReactReduxContext = {} as any
export { default as shallowEqual } from './utils/shallowEqual'
10 changes: 10 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export default defineConfig((options) => {
dts: true,
clean: true,
},
// ESM for RSC
{
...commonOptions,
entry: {
rsc: 'src/index-rsc.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: false,
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
{
...commonOptions,
Expand Down

0 comments on commit bec3fa7

Please sign in to comment.