Skip to main content
Active reading [<https://en.wiktionary.org/wiki/rerender#Verb> <https://en.wikipedia.org/wiki/Sentence_clause_structure#Run-on_sentences> (see also <https://twitter.com/PeterMortensen/status/1199839973215739907>)].
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 110
  • 134

I found this to be good, instead. Instead of defining state  (Approachapproach 1) as, example,

const initialValue = 1;
const [state,setState] = useState(initialValue)

Try this approach  (Approachapproach 2),

const [state = initialValue,setState] = useState()

This resolved the re-renderrerender issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S.: If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state, so approach 1 shall be used in this situation.

I found this to be good, instead of defining state(Approach 1) as, example,

const initialValue = 1;
const [state,setState] = useState(initialValue)

Try this approach(Approach 2),

const [state = initialValue,setState] = useState()

This resolved the re-render issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S. If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state so approach 1 shall be used in this situation.

I found this to be good. Instead of defining state  (approach 1) as, example,

const initialValue = 1;
const [state,setState] = useState(initialValue)

Try this approach  (approach 2),

const [state = initialValue,setState] = useState()

This resolved the rerender issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S.: If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state, so approach 1 shall be used in this situation.

Dragon::Supervised edit (descriptions not implemented)
Source Link

I found this to be good, instead of defining state(Approach 1) as, example,

const initialValue = 1;

const initialValue = 1;

const [state,setState] = useState(initialValue)

const [state,setState] = useState(initialValue)

Try this approach(Approach 2),

const [state = initialValue,setState] = useState()

const [state = initialValue,setState] = useState()

This resolved the re-render issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S. If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state so approach 1 shall be used in this situation.

I found this to be good, instead of defining state(Approach 1) as, example,

const initialValue = 1;

const [state,setState] = useState(initialValue)

Try this approach(Approach 2),

const [state = initialValue,setState] = useState()

This resolved the re-render issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S. If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state so approach 1 shall be used in this situation.

I found this to be good, instead of defining state(Approach 1) as, example,

const initialValue = 1;
const [state,setState] = useState(initialValue)

Try this approach(Approach 2),

const [state = initialValue,setState] = useState()

This resolved the re-render issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S. If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state so approach 1 shall be used in this situation.

Source Link

I found this to be good, instead of defining state(Approach 1) as, example,

const initialValue = 1;

const [state,setState] = useState(initialValue)

Try this approach(Approach 2),

const [state = initialValue,setState] = useState()

This resolved the re-render issue without using useEffect since we are not concerned with its internal closure approach with this case.

P.S. If you are concerned with using old state for any use case then useState with useEffect needs to be used since it will need to have that state so approach 1 shall be used in this situation.