im using the DND5E API and react. i call the data and save it to a variable called primaryChoices
, which is an array starting at `proficiency_choices in the api under the classes section (https://www.dnd5eapi.co/api/classes/monk).
i iterate over that with .map
and from that i use element.from.options
, also an array, and iterate over that with a nested .map
and extract the value of options.item.index
.
that logic works for every class except monk. its set up the same as every other class in the api and even logs correctly outside the .map
functions with this
console.log(primaryChoices[0].from.options[0].item.index)
that same console log logs the other classes too, and i can even display any information from them with no errors.
// after the data is called from the api it gets saved to character.class.primary
const primaryChoices = character?.class?.primary?.proficiency_choices
if(!isPrimaryEmpty && isSecondaryEmpty){
return (primaryChoices.map((element) => (
<div>
<strong>Choose {`${element.choose}`} for {`${primary.name}`}</strong>
{element.from.options.map((option) => {
return(
<p>
<input onChange={(e) => handleCheck(e, element, option)} type='checkbox' name={option.item.index} />
<label htmlFor={option.item.index}>{option.item.name}</label>
</p>
)
})}
</div>
)))
}else if(...){...}
the element.choose
and primary.name
both work fine with any class
i checked the path and it logs correctly without throwing errors and i went to the api page and double checked the path.
dfgghgfbfgbfgghggfggbgbgbdgbghngfdgnhdnfgngnfn
Laksh Diyora is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.