From f49f749891d04abaf741a03c4d179ddc5eadee36 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 19 Feb 2021 21:50:58 -0500 Subject: [PATCH] fix(striker-ui): allow atom ToggleSwitch to update when props change --- striker-ui/components/atoms/ToggleSwitch.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/striker-ui/components/atoms/ToggleSwitch.tsx b/striker-ui/components/atoms/ToggleSwitch.tsx index 03cc1cdc..400a9e76 100644 --- a/striker-ui/components/atoms/ToggleSwitch.tsx +++ b/striker-ui/components/atoms/ToggleSwitch.tsx @@ -1,4 +1,4 @@ -import { FunctionComponent, useState } from 'react'; +import { FunctionComponent, useEffect, useState } from 'react'; import styled from 'styled-components'; import DEFAULT_THEME from '../../lib/consts/DEFAULT_THEME'; @@ -61,6 +61,11 @@ const ToggleSwitch: FunctionComponent = ({ }) => { const [on, setOn] = useState(checked); + // Update the toggle switch when supplied props change + useEffect(() => { + setOn(checked); + }, [checked]); + return (