A
A
alaskafx2022-04-07 15:16:45
React
alaskafx, 2022-04-07 15:16:45

Is it ok to use in React components?

I saw many examples where "empty" tags were used in components , and also where they were not used. This is where the question comes in: is it good practice (or even "tone") to write such empty tags in React components? <> ... </>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Ne7Le4Der, 2022-04-07
@alaskafx

JSX only allows one block to be returned, i.e.

<div>Первый блок</div>
<div>Второй блок</div>

you cannot return. In order not to produce extra parent divs, there is one in which you can wrap several blocks and return them. In the DOM that the browser renders to you, it will not be displayed in any way. and a record is just a short record of a fragment. Well, in fact, the answer was given above - use if necessary, there is nothing wrong with that)
<React.Fragment></React.Fragment>
<></>

L
low molecular macro, 2022-04-07
@molekulyarniy

used as needed, it's not a matter of good or bad tone

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question