this.setState and following function are not even running

It’s not logging the item of "this.state.UsersAvatars[1]", nor the "check". it’s also not changing the array, the only item in UsersAvatars is the first object

Can I please ask for your help? (:

  newUserTypeAvatarsArray = async () => {
    const avatars = this.state.avatars.map((avatar, index) => ({
      avatar: avatar,
      isChcecked: false,
      index: index,
    }));
    console.log(avatars);
    let singleUser = {
      userType: "everyone",
      isChecked: false,
      avatars: avatars,
    };
    await this.setState(
      {
        UsersAvatars: [singleUser],
      },
      () => {
        console.log(this.state.UsersAvatars[0]);
      }
    );

    await this.state.users_types.map(async (userTypee, index) => {
      console.log("in loop users_types");
      const temporaryObject = {
        userType: userTypee,
        isChecked: false,
        avatars: avatars,
      };
      let temporaryArray = await [...this.state.UsersAvatars, temporaryObject];
      await this.setState(
        (prevState) => (
          {
            UsersAvatars: temporaryArray,
          },
          function () {
            console.log("check");
            console.log(this.state.UsersAvatars[1]);
          }
        )
      );
    });
    await this.setState({
      UsersAvatarsLoading: false,
    });
  };

62 thoughts on “this.setState and following function are not even running”

  1. 746230 755036Hi there, i just thought i would publish and now let you know your websites style is truly smudged within the K-Melon browser. Anyhow preserve inside the quite excellent function. 920241

    Reply
  2. 221681 823805Wow, incredible blog layout! How long have you been blogging for? you make blogging appear easy. The overall look of your web site is fantastic, as properly as the content material! xrumer 814307