From 35144ad7bd839037e3d57941dcec72a1257b4aa1 Mon Sep 17 00:00:00 2001 From: Jeremie Pardou-Piquemal <571533+jrmi@users.noreply.github.com> Date: Wed, 24 Jun 2020 22:22:50 +0200 Subject: [PATCH] New game button --- src/components/GameController.js | 9 +++++++++ src/components/NewItems.js | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/GameController.js b/src/components/GameController.js index 96e4479..5e09775 100644 --- a/src/components/GameController.js +++ b/src/components/GameController.js @@ -70,6 +70,14 @@ export const GameController = ({ availableItemList, boardConfig }) => { [c2c] ); + const newGame = React.useCallback(() => { + loadGame({ + items: [], + availableItems: [], + board: { size: 1000, scale: 0.5 }, + }); + }, [loadGame]); + const loadTikTok = React.useCallback(() => { tiktok.availableItems = []; loadGame(tiktok); @@ -141,6 +149,7 @@ export const GameController = ({ availableItemList, boardConfig }) => { return ( {t("Games")} + diff --git a/src/components/NewItems.js b/src/components/NewItems.js index 2f84b31..1c7974e 100644 --- a/src/components/NewItems.js +++ b/src/components/NewItems.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { memo } from "react"; import { useItems } from "../components/Board/Items"; import { nanoid } from "nanoid"; import { useTranslation } from "react-i18next"; @@ -14,7 +14,7 @@ const itemTemplates = { dice: {}, }; -const NewItem = ({ type }) => { +const NewItem = memo(({ type }) => { const { t } = useTranslation(); const { pushItem } = useItems(); @@ -35,7 +35,9 @@ const NewItem = ({ type }) => { {t(type)} ); -}; +}); + +NewItem.displayName = "NewItem"; const NewItems = () => { return ( @@ -49,4 +51,4 @@ const NewItems = () => { ); }; -export default NewItems; +export default memo(NewItems);