Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
What is v-if in react

What is v-if in react? I tried this but My div with loading class does not work when the loading data changes, so the div doesn't re-render itself. codes is here:

{
    loading &&
    <div className="loading"></div>
}

I'm changing loading with a function, this function working with onclick event.

all of my code:

import React from "react";
import axios from "axios";
export class LoginPage extends React.Component{
    render(){
        let username = '',
            password = '',
            loading = false

        function login(){
            loading = true;
            console.log(loading)
        }

        return (
            <div className="App">
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
                      integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA=="
                      crossOrigin="anonymous" referrerpolicy="no-referrer"/>
                        {
                            loading &&
                            <div className="loading"></div>
                        }
                <div className="login">
                    <h1>Login/Register</h1>
                    <div>
                        <i className="fas fa-user"></i>
                        <input type="text" onChange={(e) => username = e.target.value} placeholder="Username" maxLength="15"/>
                    </div>
                    <div>
                        <i className="fas fa-lock"></i>
                        <input type="Password" placeholder="Password" onChange={(e) => password = e.target.value} maxLength="18"/>
                    </div>
                    <button onClick={() => login()}>Login/Register</button>
                </div>
            </div>
        );
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'd suggest you read about React State, some things in this piece of code are wrong. But let's fix your problem.

First add this variable to the state and then change it with setState, to trigger a rerender:

export class LoginPage extends React.Component{
    constructor(props) {
      super(props);
      this.state = {
        loading: false
      };
    }

    login(){
      this.setState({ loading: true })
      console.log(this.state.loading)
    }

    render(){
      let username = '',
          password = '',

      // your return will stay the same
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!