Code Monkey home page Code Monkey logo

Comments (6)

klendi avatar klendi commented on May 26, 2024

Hello. What version of the package are you using? And share the code so I can see

from react-top-loading-bar.

char-chen avatar char-chen commented on May 26, 2024

Version: 1.1.1

constructor(props) {
    super(props);
    this.state = { loadingBarProgress: 0 };
}
onLoaderFinished = () => {
    this.setState({ loadingBarProgress: 0 });
};
componentDidMount() {
    this.setState({loadingBarProgress : 100})
}

<LoadingBar
          progress={this.state.loadingBarProgress}
          height={3}
          color='orange'
          onLoaderFinished={() => this.onLoaderFinished()}
        />

The page that use to test this out with doesn't have a white background. Therefore I had to do

<LoadingBar
          progress={this.state.loadingBarProgress}
          height={this.state.loadingBarProgress !== 0 ? 3 : 0}
          color='orange'
          onLoaderFinished={() => this.onLoaderFinished()}
        />

in order to hide the top white bar.
Is there a better way to do this?

from react-top-loading-bar.

klendi avatar klendi commented on May 26, 2024

I would use the one with refs

import React, { Component } from 'react'

import LoadingBar from 'react-top-loading-bar'

export default class ExampleWithRefs extends Component {
  startFetch = () => {
    this.LoadingBar.continuousStart()
  }

  onFinishFetch = () => {
    this.LoadingBar.complete()
  }

  render() {
    return (
      <div>
        <LoadingBar onRef={ref => (this.LoadingBar = ref)} />

        <button onClick={() => this.LoadingBar.continuousStart()}>
          Start Continuous Bar
        </button>
        <button onClick={() => this.LoadingBar.staticStart()}>
          Start Static Bar
        </button>
        <button onClick={() => this.LoadingBar.complete()}>Complete</button>
        <br />
        <button onClick={() => this.LoadingBar.add(10)}>Add 10</button>
        <button onClick={() => this.LoadingBar.add(10)}>Add 30</button>
      </div>
    )
  }
}```

Check out this example

from react-top-loading-bar.

char-chen avatar char-chen commented on May 26, 2024

Is there an example for using it in functional components?

from react-top-loading-bar.

klendi avatar klendi commented on May 26, 2024

Look the example up. You can use a functional component

from react-top-loading-bar.

klendi avatar klendi commented on May 26, 2024

I am closing this. Feel free to reopen

from react-top-loading-bar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.