I have a few elements that are essentially the same that I'm trying to refactor to be neater. The main difference is that they refer to different variables of a similar format.
For example:
(!editingTelephone && telephone === '') && 'No landline number added'}
and
(!editingMobile && mobile === '') && 'No mobile number added'
I'm wanting to be able to pass a string such as 'telephone' or 'mobile' to a function to do the construction of the whole component that will fill in all of the relevant variable names and content.
My struggle is dynamically constructing the variable names such that they call correctly...
I know that eval()
is available to use when it comes constructing variable names via strings, but I also know that this is warned against from using, from a security perspective... I'm just wondering if there is something else, safer that I can use, or would this be fine to use in React from a security perspective in this instance given that I'm not exactly exposing anything major?