C
C
CHtommy2022-04-13 21:15:19
JavaScript
CHtommy, 2022-04-13 21:15:19

Why doesn't .includes check for the existence of an array?

Hello, I can't figure out why I'm getting all elements "disabled" (using either classNames).

const typeNames = ['settings1', 'settings2'];
    const [activeType, setActiveType] = useState(0);

    const onSelectType = (index) => {
        setActiveType(index)
    }

className={classNames("item_settings",{ active: activeType === index && types.includes(index), disabled: !types.includes(index)})}

I get an array of elements through the API and compare them with typeNames (my own) and through the comparison I turn off those elements that are not in the array passed through the API
, i.e. typeNames = 0 , 1 , if everything matches in api (0, 1 ) then the elements are all active, if not, then one of them becomes disabled
Classic, nothing complicated.
Did various checks - all elements passed through .map - have true. I parsed the resulting array from the API - the data is updated, all edits come without errors.
There are no errors in the console with the strict mod.
How to debug - I can not understand.
The component itself is rendered through .map with the actual
redux data, I don’t use
upd: I also run the components themselves through .map with key. Accordingly, each position generates its own block

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CHtommy, 2022-04-14
@CHtommy

Thanks to everyone who wrote ... The problem was apparently in the API, somewhere inside the system. The array of numbers "types" simply did not want to output numbers normally, I tried to enter everything from the beginning and it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question