How do I correct my functional React component using the incorrect state data?

I use React and Typescript for my web app front-end and have functional components as such:

TrackerList contains: Header and TrackerListContent
TrackerListContent contains: StyledAlert
Header contains: HeaderUserIcon
HeaderUserIcon contains: StyledAlert

The StyledAlert is an independent instance in those components. The components that render those instances have their own state variables which get passed as props to the StyledAlert component respectively as such:

Contents at the bottom of the return in TrackerListContent:
<StyledAlert key="sa-tlc" title={styledAlertTitle} message={styledAlertMessage} level={styledAlertLevel} show={showStyledAlert} fingerprint={styledAlertFingerprint} blocking={true} />

Contents at the bottom of the return in HeaderUserIcon:
<StyledAlert key="sa-hui" title={styledAlertTitle} message={styledAlertMessage} type={styledAlertType} level={styledAlertLevel} show={showStyledAlert} fingerprint={styledAlertFingerprint} blocking={true} callback={navigateToDebug} />

Problem

What happens is in HeaderUserIcon, the state variables that get passed to it’s instance of StyledAlert somehow manage to affect the data in the TrackerListContent component’s instance of StyledAlert.

The components do not share state to a parent via lifting or any other method I’m aware of, I have tried naming the state variables differently so the names aren’t the same, I have ensured using React dev tools for firefox that each instance does indeed have the correct data but still it’s somehow rendering information from the completely different instance of the completely different component.

Example

I set the following in HeaderUserIcon
setStyledAlertTitle("Invalid Developer Code")
setStyledAlertMessage("The developer code you entered was not valid")
setStyledAlertLevel("error")
setStyledAlertType("alert")
setShowStyledAlert(true)
setStyledAlertFingerprint(!styledAlertFingerprint)

And I set the following in TrackerListContent
setStyledAlertLevel("warning")
setStyledAlertTitle("Rental Age")
setStyledAlertMessage("This rental is older than " + maxTimeframe + " months. Please ensure this is the correct rental you will be working with.")
setStyledAlertFingerprint(fingerprintSwitch.current)
setShowStyledAlert(true)

No matter what I name the variables the issue persists that the HeaderUserIcon title and message state that should only be used within the HeaderUserIcon component gets used in the TrackerListContent component. Strangely enough, though, the Alert Level state, which controls the color of the alert’s title bar, is correct. In the TrackerListContent component that bar should be red, or set to level of “error”, and in the HeaderUserIcon it should be gray, or set to level of “information”. These things work even though the text is wrong.

What I’ve Tried

  • Changing the state variables names so they aren’t the same in each component
  • Taking ChatGPT’s ( often horrible ) advice to wrap the component in a React.memo
  • Debugged using React dev tools to verify each instance does in fact contain the correct text
  • Manually remove the second instance from the DOM completely ( this causes the alert to render correctly )
  • Tried using a conditional render in the TrackerListContent and HeaderUserIcon components to decided whether or not to even render the StyledAlert to begin with ( same issues )
  • Ensured my StyledAlert components have unique keys

Any help would be appreciated.

New contributor

brandononso is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật