From 3669c6c41d597e65ed68d1b8c188c1c66e63bf83 Mon Sep 17 00:00:00 2001 From: baranero Date: Wed, 1 Mar 2023 10:48:06 +0100 Subject: [PATCH] fixed bug in react 18 with children prop --- code/16-finished/.gitignore | 25 ++++++++++++++++++++ code/16-finished/src/store/todos-context.tsx | 4 +++- package-lock.json | 6 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 code/16-finished/.gitignore create mode 100644 package-lock.json diff --git a/code/16-finished/.gitignore b/code/16-finished/.gitignore new file mode 100644 index 0000000000..3dc0a5dba7 --- /dev/null +++ b/code/16-finished/.gitignore @@ -0,0 +1,25 @@ +.DS_Store +.vscode +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/code/16-finished/src/store/todos-context.tsx b/code/16-finished/src/store/todos-context.tsx index 334a2a0aa7..5bfd447709 100644 --- a/code/16-finished/src/store/todos-context.tsx +++ b/code/16-finished/src/store/todos-context.tsx @@ -14,7 +14,9 @@ export const TodosContext = React.createContext({ removeTodo: (id: string) => {}, }); -const TodosContextProvider: React.FC = (props) => { +// In React 18.x you have to include the children prop yourself, I wrote solution below + +const TodosContextProvider: React.FC<{ children: JSX.Element | JSX.Element[] }> = (props) => { const [todos, setTodos] = useState([]); const addTodoHandler = (todoText: string) => { diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000..da3d09de9f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "react-complete-guide-code", + "lockfileVersion": 2, + "requires": true, + "packages": {} +}