Skip to content

Commit

Permalink
Fix TypeScript issue with returning ReactNode from FC
Browse files Browse the repository at this point in the history
  • Loading branch information
penspinner committed Jun 30, 2019
1 parent 895273c commit f43395f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This package was inspired by Dan Abramov's talk about React async rendering and

| Property | Type | Required? | Default | Description |
| :------- | :-------- | :-------: | :------ | :--------------------------------------------------- |
| children | ReactNode | | | The React node that will be rendered (eg `<div />`). |
| children | ReactNode | | `null` | The React node that will be rendered (eg `<div />`). |

<br>

Expand Down
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode, useEffect, useState } from 'react';
import { FC, ReactElement, ReactNode, useEffect, useState } from 'react';

import globalObject from './globalObject';

Expand All @@ -10,11 +10,7 @@ const cancelSchedule = globalObject.cancelIdleCallback
? globalObject.cancelIdleCallback
: globalObject.clearTimeout;

interface ITimeSlicerProps {
children: ReactNode;
}

const TimeSlicer = ({ children }: ITimeSlicerProps) => {
const TimeSlicer: FC = ({ children }) => {
const [previousChildren, setPreviousChildren] = useState<ReactNode>(null);

useEffect(() => {
Expand All @@ -25,7 +21,8 @@ const TimeSlicer = ({ children }: ITimeSlicerProps) => {
return () => cancelSchedule(scheduler);
});

return previousChildren;
// https://stackoverflow.com/questions/54905376/type-error-jsx-element-type-null-undefined-is-not-a-constructor-functi
return previousChildren as (ReactElement | null);
};

export default TimeSlicer;

0 comments on commit f43395f

Please sign in to comment.