ReactJS - load the data before rendering the component

ReactJS - load the data before rendering the component

Content Index :

ReactJS - load the data before rendering the component
Tag : reactjs , By : liquidx
Date : January 12 2021, 08:33 AM

wish helps you The way you are doing it, you could validate the response state object in your render method, and if it is null/empty, then return
When your state is then updated based on the response, the component will automagically re-render. This time, the object will be populated and you can return your component HTML.

    if (!this.state.response){
        return <div>Loading...</div>

    return (
        <div>Proper Stuff</div>

    this.state = {
        response: {...}

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

ReactJS component rendering and how to append elements to the div the component is mounted on

Tag : reactjs , By : m0gb0y74
Date : March 29 2020, 07:55 AM
Hope this helps OK, your question wasn't clear on this, but the data that is represented by what was generated in the HTML will be entirely different from the data that you will be getting via AJAX.
There's a simple solution to this. Instead of creating an entirely new DOM element that will be adjacent to your original DOM layout, what you will do is grab the data that was already there, store it into an array, and append the new data that you will grab via AJAX into that Array. This way, you will reap the benefit of React's DOM diffing. Why is it useful? Maybe you want to let the user sort the data, or interact with the data directly, while it will remain in full control of a parent React component.
var Page = React.createClass({ 
  getDefaultProps: function () {
    return {
      items: []
  getInitialState : function(){
      items : this.props.items
  componentDidMount: function () {
    // Mimics an AJAX call, but replace this with an actial AJAX call.
    setTimeout(function () {
      var dataFromAjax = ['one', 'two', 'three'];
        items: this.state.items.concat(dataFromAjax)
  addClick : function(){
  render : function(){
    return <div>{this.state.items.map(function(item){return <div className="bla-bla-class">{item}</div>})}<br/><div onClick={this.addClick}>ADD</div></div>;

var elements = document.querySelectorAll('.item-list__child-item');

var initialvalues = Array.prototype.slice
  .map(function (div) {
    return div.innerHTML;

React.render(<Page items={initialvalues} />, document.body);

How to pass data in server side rendering to reactjs component from node

Tag : node.js , By : enginecrew
Date : March 29 2020, 07:55 AM
Any of those help I am very new to reactJs and just started to learn the features of reactJS. I am trying to figure out a way to pass the value from nodeJS to reactJS via server side rendering concept.
ReactElement createElement(
    string/ReactClass type,
    [object props],
    [children ...]
React.createElement(Component, {obj: obj, ...: ...})

How can I load the data before the component in ReactJS?

Tag : javascript , By : n1ckless_id
Date : October 16 2020, 03:08 PM
Hope this helps Your current implementation does not utilise your React Component's state.
At the moment, your arr value is simply attached to this, therefore, React cannot see when it changes.
constructor(props) {
   this.state: {
     arr: []
  arr: response
const arr = this.state.arr

How can load data of lists using component in ReactJS?

Tag : javascript , By : ChristianM
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You are returning undefined in your map-function.
Try changing to this:
const listItems = numbers.map( (number) => {
  return <ListItem key={number.toString()} value={number} />
// By omitting the {} around the callback function body
// you can utilise the implicit-returning feature of arrow functions.
const listItems = numbers.map( (number) => (
  <ListItem key={number.toString()} value={number} />

// The above example is the same as:
const listItems = numbers.map( (number) => <ListItem key={number.toString()} value={number} />);

how to change a component without rendering the other component in reactjs and react-router-dom

Tag : javascript , By : Imran
Date : March 29 2020, 07:55 AM
it helps some times You would need a route for each post that is rendered via url parameters. Notice :id for rendering a specific post. When that post is reached it can fetch its needed data as well.
  render () {
    return (
          render={() => {
            return (
Related Posts Related QUESTIONS :
  • Rendered more hooks than during the previous render. when posting form data with React Hooks
  • How can I envoke <Link to=''> route transition from a custom function?
  • How to change certain div color base on number
  • Hide Navbar on some routes (React Router v5)
  • is it safe to ignore react's warning about calling the useState hook conditionally when only the parameter is conditiona
  • How to pass a function as a prop to React function component?
  • Creating a function that replace a letter with a line break
  • How to add and remove property from Redux state
  • Can I, (and should I), make assertions about what HTML elements a component renders using Enzyme's shallow()?
  • Testing function calls in Jest after button click (mocking fetch calls)
  • How can I show a card shadow on all sides?
  • Jest - Map through an Array of Items and test their Values
  • Run Effect hook only when both dependencies change
  • What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So wh
  • Font size of tooltip in speeddialaction of React's Material UI
  • Module Not Found - Webpack Dev Server
  • React not rendering all elements within a list of components
  • How to change attribute of a React Element
  • ReactJs: How to back focus to input field after resetting the form
  • Multilanguage in react using redux
  • React JS — how do I add child components and set calculated transformations?
  • ReactJS componentDidUpdate() prevState equals to currentState
  • TypeScript error: JSX element type 'Tree' does not have any construct or call signatures. I'm not able to import my own
  • createProvider is not exported from react-redux?
  • Error:(19, 35) TS2304: Cannot find name 'T'. Why I can't extend interface in TS?
  • How can I secure images in S3 buckets with Auth0 and a React front-end
  • React Import Multiple Functions
  • React render when props change
  • Cannot read property 'array' of undefined
  • What is the expected return of `useEffect` used for?
  • Why i need to install npm for react native app
  • How to fix 'module not found' for audio files using file-loader? Images, CSS, and JSON are working just fine
  • Can't render the component received as a prop.children in my parent component
  • rootInstance.findByType("input"); Giving Expected 1 but found 2 instances with node type : "undefined&quo
  • Reset state to initial state only for specific state variables
  • Get error TS2322: Type 'any' is not assignable to type 'never'
  • Is it possible to update the store outside of the Provider context in Redux?
  • Copy to clipboard is copying value with two newlines
  • How to test useRef with the "current" prop in jest/enzyme
  • How to remove value of each key in Async Storage in React Native at the time of Logout
  • Is there a simpler way to write this React code
  • Auth0. How to get user's permissions in access token?
  • this.setState is not updating the state property
  • for loops in reacts js
  • The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, http://localhost:3000', but on
  • Slowly implementing redux to an existing React.js project
  • how to use document.querySelector().innerHTML in react
  • Pass params to firestore collections
  • BrowserRouter vs Router with history.push()
  • React Formik onSubmit RestAPI called twice, once click a submit button
  • Can this assignment be made simpler by destructuring?
  • Manually fire a query via compose( graphql() )
  • Why not maintain state in localStorage if redux loses state on refresh?
  • How to remove duplicated before map
  • How to write date in a field with date format?
  • How to listen to localstorage value changes in react?
  • Apollo local state - querying for object w unknown keys
  • Submit works with second try
  • Error : Cannot read property 'mountComponent' of undefined
  • How to export module properly so vscode can show my module in suggestion [ctrl+space]?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com