Skip to content

Commit

Permalink
fix(react): ssr
Browse files Browse the repository at this point in the history
fix #32
  • Loading branch information
sneas committed Jun 18, 2021
1 parent d29e14c commit e023ebe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bindings/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "React wrapper for img-comparison-slider",
"homepage": "https://sneas.github.io/img-comparison-slider",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/"
Expand All @@ -17,7 +16,8 @@
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "rimraf dist",
"compile": "npm run tsc",
"compile": "tsc",
"watch": "tsc --watch",
"tsc": "tsc -p ."
},
"devDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions bindings/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React, { FC, AllHTMLAttributes, PropsWithChildren } from 'react';
import 'img-comparison-slider';

if (typeof document !== 'undefined') {
import('img-comparison-slider');
}

type ImgComparisonSliderProps = AllHTMLAttributes<HTMLElement>;

export const ImgComparisonSlider: FC<ImgComparisonSliderProps> = ({
children,
...props
}: PropsWithChildren<ImgComparisonSliderProps>) =>
React.createElement(
}: PropsWithChildren<ImgComparisonSliderProps>) => {
return React.createElement(
'img-comparison-slider',
Object.assign({}, props),
children
);
};
4 changes: 2 additions & 2 deletions bindings/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"lib": ["dom", "es2015"],
"module": "es2015",
"module": "CommonJS",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
Expand All @@ -17,7 +17,7 @@
"removeComments": false,
"sourceMap": true,
"jsx": "react",
"target": "es2015"
"target": "ESNext"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["**/__tests__/**"],
Expand Down

0 comments on commit e023ebe

Please sign in to comment.