diff --git a/example-js/src/App.js b/example-js/src/App.js index 18a7984..ff407be 100644 --- a/example-js/src/App.js +++ b/example-js/src/App.js @@ -23,6 +23,15 @@ const App = () => { const MasterProvider = composeWrappers([ props => , props => {props.children}, + props => { + const p1 = React.useContext(P1); + const p4 = React.useContext(P4); + return <> + P1 from wrapper: {p1.p1} + P4 from wrapper: {p4.p4} + {props.children} + + }, props => {props.children}, props => {props.children}, ]); diff --git a/example-js/src/App.test.js b/example-js/src/App.test.js index e4a7b46..c3fe14c 100644 --- a/example-js/src/App.test.js +++ b/example-js/src/App.test.js @@ -6,6 +6,8 @@ test('JS', () => { const { getByText } = render(); expect(getByText('P1: foo', {exact: false})).toBeInTheDocument(); expect(getByText('P2: bar', {exact: false})).toBeInTheDocument(); + expect(getByText('P1 from wrapper: foo', {exact: false})).toBeInTheDocument(); + expect(getByText('P4 from wrapper: p4', {exact: false})).toBeInTheDocument(); expect(getByText('P3: baz', {exact: false})).toBeInTheDocument(); expect(getByText('P4: qaz', {exact: false})).toBeInTheDocument(); }); diff --git a/example-ts/src/App.test.tsx b/example-ts/src/App.test.tsx index 0f1ab6d..8022ff7 100644 --- a/example-ts/src/App.test.tsx +++ b/example-ts/src/App.test.tsx @@ -6,6 +6,8 @@ test('TS', () => { const { getByText } = render(); expect(getByText('P1: foo', {exact: false})).toBeInTheDocument(); expect(getByText('P2: bar', {exact: false})).toBeInTheDocument(); + expect(getByText('P1 from wrapper: foo', {exact: false})).toBeInTheDocument(); + expect(getByText('P4 from wrapper: p4', {exact: false})).toBeInTheDocument(); expect(getByText('P3: baz', {exact: false})).toBeInTheDocument(); expect(getByText('P4: qaz', {exact: false})).toBeInTheDocument(); }); diff --git a/example-ts/src/App.tsx b/example-ts/src/App.tsx index fb7849b..eb81865 100644 --- a/example-ts/src/App.tsx +++ b/example-ts/src/App.tsx @@ -23,6 +23,15 @@ const App: React.FunctionComponent = () => { const MasterProvider = composeWrappers([ props => , props => {props.children}, + props => { + const p1 = React.useContext(P1); + const p4 = React.useContext(P4); + return <> + P1 from wrapper: {p1.p1} + P4 from wrapper: {p4.p4} + {props.children} + + }, props => {props.children}, props => {props.children}, ]); diff --git a/index.ts b/index.ts index 57caa54..5564108 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,7 @@ import React from 'react'; export const composeWrappers = ( wrappers: React.FunctionComponent[] ): React.FunctionComponent => { - return wrappers.reduce((Acc, Current): React.FunctionComponent => { + return wrappers.reduceRight((Acc, Current): React.FunctionComponent => { return props => React.createElement( Current, null, diff --git a/package.json b/package.json index 68825a2..b1ed87d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-compose-wrappers", - "version": "0.0.0", + "version": "0.1.0", "description": "Compose multiple React component wrappers", "main": "index.js", "scripts": {