Skip to content

Commit

Permalink
fix(react): export utility components from a separate index (#889)
Browse files Browse the repository at this point in the history
Using commonjs exports and exporting them from the main index means that if a user is importing the components into a bundler, the bundler will also try to bundle the main adapter code, which is not meant for bundling and will error out.
  • Loading branch information
mihkeleidast committed Mar 20, 2021
1 parent 7acc0c4 commit 00ca0ec
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/react/components/path/path.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');

const { usePath } = require('@frctl/react');
const { usePath } = require('@frctl/react/components');

const Path = () => {
const path = usePath();
Expand Down
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fractal.components.engine(reactAdapter);
The adapter exposes a React Context Provider component called PathProvider to allow usage of relative paths in static HTML exports. The rendered components and preview layouts are automatically wrapped with it.

```js
const { PathProvider, PathContext, usePath } = require('@frctl/react');
const { PathProvider, PathContext, usePath } = require('@frctl/react/components');

const Button = (props) => {
// use via useContext hook
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/react/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const PathProvider = require('./path-provider');

module.exports = {
PathProvider: PathProvider,
PathContext: PathProvider.PathContext,
usePath: PathProvider.usePath,
};
File renamed without changes.
5 changes: 0 additions & 5 deletions packages/react/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
'use strict';

const { PathProvider } = require('./src/components');

module.exports = require('./src/adapter');
module.exports.PathProvider = PathProvider;
module.exports.PathContext = PathProvider.PathContext;
module.exports.usePath = PathProvider.usePath;
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.2.0",
"description": "React template adapter for Fractal.",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/frctl/fractal.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const ReactDOM = require('react-dom/server');

const { Adapter, utils } = require('@frctl/core');

const PathProvider = require('../components/path-provider');
const clearModule = require('./clear-module');
const PathProvider = require('./components/path-provider');

/*
* React Adapter
Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/components/index.js

This file was deleted.

0 comments on commit 00ca0ec

Please sign in to comment.