Skip to content

Commit

Permalink
Revert "Wrap synthesize value calls in useEffect" (#139776)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsummers1 authored Sep 24, 2024
1 parent 56ef3e3 commit f4cbb13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
37 changes: 16 additions & 21 deletions services/ui-src/src/components/fields/SynthesizedTable.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useEffect, useState } from "react";
import React from "react";
import { useSelector, shallowEqual } from "react-redux";
//utils
import synthesizeValue from "../../util/synthesize";
//types
import PropTypes from "prop-types";

const SynthesizedTable = ({ question, tableTitle }) => {
const [rows, setRows] = useState([]);
const [allStatesData, stateName, stateUserAbbr, chipEnrollments, formData] =
useSelector(
(state) => [
Expand All @@ -19,26 +18,22 @@ const SynthesizedTable = ({ question, tableTitle }) => {
shallowEqual
);

useEffect(() => {
const rows = question.fieldset_info.rows.map((row) =>
row.map((cell) => {
const value = synthesizeValue(
cell,
allStatesData,
stateName,
stateUserAbbr,
chipEnrollments,
formData
);
const rows = question.fieldset_info.rows.map((row) =>
row.map((cell) => {
const value = synthesizeValue(
cell,
allStatesData,
stateName,
stateUserAbbr,
chipEnrollments,
formData
);

return typeof value.contents === "number" &&
Number.isNaN(value.contents)
? { contents: "Not Available" }
: value;
})
);
setRows(rows);
}, [allStatesData, stateName, stateUserAbbr, chipEnrollments, formData]);
return typeof value.contents === "number" && Number.isNaN(value.contents)
? { contents: "Not Available" }
: value;
})
);

return (
<div className="synthesized-table ds-u-margin-top--2">
Expand Down
25 changes: 10 additions & 15 deletions services/ui-src/src/components/fields/SynthesizedValue.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React from "react";
import { useSelector, shallowEqual } from "react-redux";
//components
import Question from "./Question";
Expand All @@ -8,7 +8,6 @@ import synthesizeValue from "../../util/synthesize";
import PropTypes from "prop-types";

const SynthesizedValue = ({ question, ...props }) => {
const [displayValue, setDisplayValue] = useState();
const [allStatesData, stateName, stateUserAbbr, chipEnrollments, formData] =
useSelector(
(state) => [
Expand All @@ -21,22 +20,18 @@ const SynthesizedValue = ({ question, ...props }) => {
shallowEqual
);

useEffect(() => {
setDisplayValue(
synthesizeValue(
question.fieldset_info,
allStatesData,
stateName,
stateUserAbbr,
chipEnrollments,
formData
).contents
);
}, [allStatesData, stateName, stateUserAbbr, chipEnrollments, formData]);
const value = synthesizeValue(
question.fieldset_info,
allStatesData,
stateName,
stateUserAbbr,
chipEnrollments,
formData
).contents;

return (
<div>
<strong>Computed:</strong> {displayValue}
<strong>Computed:</strong> {value}
{question.questions &&
question.questions.map((q) => (
<Question key={q.id} question={q} {...props} />
Expand Down

0 comments on commit f4cbb13

Please sign in to comment.