1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
TEA [102]
3 years ago
14

How to add if an statemement on a retrun in react js.

Computers and Technology
1 answer:
miv72 [106K]3 years ago
3 0

Answer:

Of course, if we think about if statement in Javascript or Typescript logic, it’s the same as in every Javascript or Typescript place.

It’s just if/else like pure javascript, but in this case, we won’t talk about the normal if/else.

In react, we’ll need if statements for the one more thing, it’s the rendering.

It’s named “Conditional rendering”, but to make it simple, let’s stay with “if statement in react”.

There are the two most popular ways to use conditional rendering that we’ll see in the React.js code, and depends on a case, both of them are correct.

The first way that we can use is to define the conditional rendering directly in the components layout.

It’s quick and easy that we’ll use the most, and in some cases, it is the best for performance.

We’ll be using this way in the cases when we have only one condition, more just as “if”, when we would like to render some element when a specified condition is passed.

The second way is the function created to handle specified parts of the layout, and render it conditionally, to do that we can use not only if/else but the switch case as well.

This one way is right to use in cases where we have more conditions, especially the version with switch one.

But it fires the function anyway, so it is no sense to use it when we have one condition.

Let’s take a look at the code examples where I added both ways of doing that:

// The first example with the code inside functional component

function Parent(props) {

 return(

   <>

     {name === "Duomly" && (

       <DuomlyComponent/>  

     )}

   </>

 )

}

// The second example with the additional function

function renderComponent() {

 const name = 'Duomly';

 if (name === 'Duomly') {

   return 'Duomly';

 } else {

   return null;

 }

}

function Parent(props) {

 return renderComponent();

}

Explanation:

You might be interested in
which program monitors the computer by looking for known trouble makers as well as suspicious behavior​
lys-0071 [83]

Answer:

i think spyware because spyware can collect almost any type of data, including personal information like internet surfing habits, user logins, and bank or credit account information. Spyware can also interfere with a user's control of a computer by installing additional software or redirecting web browsers.

Explanation:

3 0
3 years ago
Which of the following is a strength of fiscal policy?
Fynjy0 [20]
The answer to your question is b crowding out effect
7 0
3 years ago
Access to sensitive or restricted information is controlled describes which of the key communications and information systems pr
Viktor [21]

Answer:

C: Security

Explanation:

Communications and information systems principles need to be, among other things, secure. They need to be able to protect sensitive information from those who intentionally not need to know. Some incident information like voice, networks, and data, are very sensitive and thus, should be secure to the right levels and should comply with privacy laws and data protection.

4 0
4 years ago
2. Feet to Inches One foot equals 12 inches. Design a function named feetToInches that accepts a number of feet as an argument,
MariettaO [177]

Answer:

See the below the answer written in Matlab

Explanation:

function inches=feetToInches(feet)

prompt='enter the value of feet in digits';

feet=input(prompt)% ask for the value in feet that needs to be converted to inches

inches =feet*12; % converts feet to inches

x=['the value in inches is:  ',num2str(inches)];

disp(x) %display the result of the convertion

end

8 0
3 years ago
How many bytes make up the word panthers
Sati [7]
It is saying 8 bytes
6 0
3 years ago
Other questions:
  • What standard linux utility is used to install and configure software on centos operating systems?
    8·1 answer
  • Framing can create which of the following in a photograph? Mystery Saturation Aperture All of the above
    10·2 answers
  • In this part, you have to implement a linked list that maintains a list of integers in sorted order. Thus, if the list contains
    13·1 answer
  • What is the difference between a sequential program and an event-driven program?
    9·1 answer
  • Prewritten, commercially available sets of software programs that eliminate the need for a firm to write its own software progra
    7·1 answer
  • . Write a swift programming code to perform following tasks a) Declare a variable that stores the age of a person b) Declare a c
    5·1 answer
  • What is it called when an attacker convinces you to enter personal information at an imposter website after receiving an email f
    10·2 answers
  • ---------------is a systematic review of a person’swork and achievements over a recent period, usually leading toplans for the f
    11·1 answer
  • Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSi
    6·1 answer
  • Who is your favorite person from squid game?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!