tratando de depurar, y no estoy seguro si esta estructura funciona...
onClick={()=>{ //2. an image is clicked, and the choice is added to the choiceOrder state, and then a jsonupdate is called -- 3. in ChooseBy.js //onclick, add or remove the choice choosebyprops.setChoiceOrder( choiceOrder=> choiceOrder.includes(attrprops.attrChoice) ? ( (choiceIndex = choiceOrder.findIndex(attrprops.attrChoice)), (choiceOrder.filter(list=> list!==attrprops.attrChoice)), (choosebyprops.setJsonList(jsonList=> jsonList.splice(choiceIndex) )) //removes the json data for that choice ) : ( ( [...choiceOrder,attrprops.attrChoice] ), (choosebyprops.setJsonList(jsonList=> [...jsonList, UpdateJson({...allprops})])) //adds json data for that choice ) ) }}básicamente estoy tratando de hacer una lista de jsons, donde si hago clic en el botón, se agrega un json filtrado a la lista para esa opción, si dejo de hacer clic en él, se elimina.
pero solo quiero saber si puedo tener varias declaraciones dentro de esa función ternaria.
No intente abusar del operador condicional como reemplazo de if / else ; if / else le permitirá crear bloques , cuyas declaraciones se pueden poner en forma mucho más natural.
Parece que estás buscando hacer algo como esto:
choosebyprops.setChoiceOrder(choiceOrder => { if (choiceOrder.includes(attrprops.attrChoice)) { const choiceIndex = choiceOrder.findIndex(attrprops.attrChoice); choosebyprops.setJsonList(jsonList => jsonList.splice(choiceIndex)); // this splice sounds wrong - don't mutate in React return choiceOrder.filter(list => list !== attrprops.attrChoice); } else { choosebyprops.setJsonList(jsonList => [...jsonList, UpdateJson({ ...allprops })]); return [...choiceOrder, attrprops.attrChoice]; } });