K
K
KnightForce2017-02-25 09:35:41
React
KnightForce, 2017-02-25 09:35:41

How many times is connetc() called?

I watched a video in which the author filters data for state in connect:

connect((state)=>({
    state.arrayValues.filter(val => val.includes(a));//массив со строками
  }),
  (dipatch)=>({})
);

And by clicking on the button, the desired results are drawn.
It turns out that connect is not called at the very beginning, but when redrawing?
Source:
Source
From 7 minutes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2017-02-25
@KnightForce

In both cases. At the beginning, since the component is probably connected somewhere, and since it is connected (for example, through import MyComp), then all the code will be executed. It is the same in case of changing the "attached" data.
The easiest way to check this is to add console.log and see.

connect( (state)=> {
    console.log('вызван connect')
    return state.arrayValues.filter(val => val.includes(a));//массив со строками
  },
  (dipatch)=>({})
);

I
Islam Ibakaev, 2017-02-25
@devellopah

shouldn't it be like this

connect( (state) => ({ filtered: state.arrayValues.filter(val => val.includes(a)) }) )(MyComponent);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question