From 07e69074ec97f185c192acfc27c472012fcbdf38 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 14 Dec 2021 12:19:48 +0000 Subject: [PATCH] move logic out to parent component. --- equations/src/App.js | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/equations/src/App.js b/equations/src/App.js index a0611a8..08f4742 100644 --- a/equations/src/App.js +++ b/equations/src/App.js @@ -3,25 +3,46 @@ import {useEffect,useState} from 'react'; import './App.css'; function Equation(p) { - const {data} = p - const [operator,setOperator] = useState("disabled") - const [field,setField] = useState(Object.keys(data)[0]) + const {data,id,equationParts,setEquationParts,field,operator} = p - return
- { + updateEquation(ev.currentTarget.value,operator) + }}> + {Object.keys(data).map((key)=>)}
- {data[field]}
+ {data[field]}
+
{id}
} function EquationBuilder(p) { const {data} = p - const [equationParts,setEquationParts] = useState([]) + const [equationParts,setEquationParts] = useState([]) + const [equation,setEquation] = useState([]) + useEffect(()=>{ + var newEq = [] + for (var i=0;i + setEquationParts([...equationParts,{field:Object.keys(data)[0],operator:"+"}])}}>+ +

+ {equationParts.map((eq,i)=>)}

- {equationParts.map((eq)=>eq)} + {equation} + } function App() {