Skip to content

Commit

Permalink
Adding FromNonStandardRednerProp demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgray committed Mar 29, 2019
1 parent db7b393 commit 0a50e1b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
55 changes: 55 additions & 0 deletions demo/demos/FromNonStandardRenderPropDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react';
import Step from '../Step';
import {
fromNonStandardRenderProp,
ChainableComponent
} from '../../src/ChainableComponent';

type MyRenderPropProps = {
foo: string;
render?: (s: string) => React.ReactElement<any> | null;
otherRender?: (n: number) => React.ReactElement<any> | null;
};

const MyRenderProp = (props: MyRenderPropProps) => (
<div>
{props.render
? props.render('string value')
: props.otherRender
? props.otherRender(5)
: null}
</div>
);

const nonStandardStr = fromNonStandardRenderProp('render', MyRenderProp, {
foo: 'asdf'
});
const nonStandardNum = fromNonStandardRenderProp('otherRender', MyRenderProp, {
foo: 'asdf'
});

export const FromNonStandardRenderPropDemo = ChainableComponent.all([
nonStandardStr,
nonStandardNum,
nonStandardNum
]).render(([foo, outer, inner]) => (
<div>
{foo}
<div>
Outer: {outer}
</div>
<div>
Inner: {inner}
</div>
</div>
));

export default () => (
<Step title="FromNonStandardRenderPropDemo Demo">
<pre className="code-sample">
{`hmm
`}
</pre>
{FromNonStandardRenderPropDemo}
</Step>
);
3 changes: 3 additions & 0 deletions demo/demos/ReactRouterDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const customHistory = createBrowserHistory();

const withRoute = fromRenderProp(Route);

// how to use 'render' instead of 'children' (react router cares about this...)
// const withOtherRoute = fromNonStandardRenderProp('render', Route)

// Route doesn't have any required props, so we can just pass the empty object here
const ReactRouterDemoInner: React.SFC = () => (
<Step title="React Router Demo">
Expand Down
1 change: 0 additions & 1 deletion demo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import '../styles/index.less';

import './demo.less';

Expand Down

0 comments on commit 0a50e1b

Please sign in to comment.