javascript – Para que serve e como definir a prop “key” no React?

javascript – Para que serve e como definir a prop “key” no React? – Stack Overflow em Português

javascript – Help in Creating a dashboard(Like the video below) using React js that contains a sidebar that includes items that the user can order to fill

link to see how it work on youtube: https://www.youtube.com/watch?v=ItnM8JzP_I8&ab_channel=eliiehachem

I want to create a dashboard like this (Using React) contains a box(this sidebar looks like a box) section that includes a list of items(cards to be filled)

where the user can assign and choose the order of filling cards (Like this video)

more like this flow Setup (in the video)

like let the user choose the order of verification himself

like he can choose proof of address before selecting a passport

Thanks!

Thanks!(!(first)(1third)(1))

security – I cannot receive API data from my localhost machine on react native expo


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




React Maximum update depth exceeded com SetInterval

Estou com um problema que não consigo resolver. Estou tentando simular a perda de água no corpo de um animal ao longo do tempo, e caso o animal esteja dormindo, a quantidade de água perdida é menor.

Dentro do primeiro UseEffect tenho um setInterval, que decrementa o estado currentValue de acordo com a prop water.decrementRate. Coloquei uma condição para que o setInterval execute somente se o animal estiver vivo. No retorno do hook eu limpo o loop com um clearInterval.

O programa funciona até o momento em que os valores da prop water.decrementRate ou do estado IsDead são alterados. No console do navegador o erro “React Maximum update depth exceeded.” ocorre iterativamente. Tentei usar as soluções que vi, colocando o array de dependencias para o useEffect, movendo a função “generateRandomNumber” para dentro do hook e utilizando Atualizações Funcionais no setState “setCurrentValue”.

Tenho o Seguinte código dentro do meu componente WaterSystem:

import { useState, useEffect } from "react";
import Container from "../Container/index"
import { useIsDead } from '../../hooks/animal.hook';
import './style.css';

const WaterSystem = ({water}) => {

    const (currentValue, setCurrentValue) = useState(water.capacity);
    const {isDead, setIsDead} = useIsDead();

    useEffect(() => {
        function generateRandomNumber() {
            const variationRate = 0.2;
            const variationValue = water.decrementRate  * variationRate;
            const max = (water.decrementRate + variationValue);
            const min = (water.decrementRate - variationValue);
            const newNumber = Math.random() * (max - min) + min;
            return newNumber;
        }

        if(!isDead){
            const id = setInterval(() => {
                setCurrentValue(oldValue => oldValue + (generateRandomNumber() * -1));
            }, 1000);
        
            return () => clearInterval(id);
        }
    }, (water.decrementRate, isDead)); 

    useEffect(() => {
        if(currentValue <= 0)
            setIsDead(true);
    }, (currentValue, setIsDead));

    useEffect(() => {
        if(!isDead){
            setCurrentValue(water.capacity);
        }
    }, (isDead, water.capacity));

    return(
        <Container>
            <p>Nivel de água (Máx <b>{water.capacity}</b> ml): <b>{currentValue.toFixed(2)}</b></p>
            <p>perda de água (ml/s): <b>{water.decrementRate}</b></p>
        </Container>
    );
}

export default WaterSystem;

Tenho o seguinte código no componente Animal:

import React from "react";

import WaterSystem from "../WaterSystem/index";
import Botao from "../Botao/index";
import { useWater, useIsDead, useIsSleeping } from '../../hooks/animal.hook';

import './style.css';

const Animal = () => {
  const {isSleeping, setIsSleeping} = useIsSleeping();
  const {isDead, setIsDead} = useIsDead();
  const water = useWater(isSleeping);

  return (
    <div>
      <h1>{isDead ? 'morto' : 'vivo'}</h1>
      <WaterSystem water={water} />
      <Botao label={isSleeping ? "awake" : "sleep"} onClick={() => setIsSleeping(!isSleeping)}/>
      {isDead && <Botao label="Reiniciar" onClick={() => setIsDead(!isDead)}/>}
    </div>
  )
};

export default Animal;

Neste arquivo estou usando 3 hooks customizados provenientes do arquivo animal.hook.js:

import { useState, useEffect, useContext } from "react";
import { AnimalContext } from "../contexts/Animal.context";

export function useWater(isSleep) {
    const values = {
        sleep: {
            capacity: 100,
            decrementRate: 6,
            drinkRate: 30,
            dehydrationRange: (0.05, 0.08, 0.1, 0.15)
        }, 
        repose: {
            capacity: 100,
            decrementRate: 10,
            drinkRate: 30,
            dehydrationRange: (0.05, 0.08, 0.1, 0.15)
        }
    };

    const (water, setWater) = useState(values.repose);

    useEffect(() => {
        if(isSleep)
            setWater(values.sleep);
        else    
            setWater(values.repose);
    }, (isSleep, values.sleep, values.repose));

    return water;
}

export function useIsDead() {
    const context = useContext(AnimalContext);
    const {isDead, setIsDead} = context;
    return {isDead, setIsDead};
}

export function useIsSleeping() {
    const context = useContext(AnimalContext);
    const {isSleeping, setIsSleeping} = context;
    return {isSleeping, setIsSleeping};
}

Na função useWater recebo um valor booleano isSleep para verificar se o animal esta dormindo e crio um objeto literal contendo os valores para cada condição do animal (dormindo e acordado). quando há mudança no isSleep, uso o useEffect para atribuir o corresponde valor no estado water e retorná-lo.

As funções useIsDead e useIsSleeping retornam os estados de um contexto criado para o animal, que está presente no arquivo Animal.context.js:

import React, { createContext, useState } from 'react';

export const AnimalContext = createContext({});

export const AnimalProvider = (props) => {
    
    const (isDead, setIsDead) = useState(false);
    const (isSleeping, setIsSleeping) = useState(false);

    return (
        <AnimalContext.Provider value={{ 
            isDead, setIsDead, 
            isSleeping, setIsSleeping
        }}>
            {props.children}
        </AnimalContext.Provider>
    );
}

json – Como atualizar um objeto dentro de um array usando states do React

Olá! O que estou tentando fazer é basicamente atualizar o estado de um objeto que está dentro de um array. Bem, esse é meu state original:

"livedata":(
   "table":(
      "data":(
         {
            "dataToUpdate":false
         }
      )
      "data2":()
)

Então, a ideia é que eu atualize o “dataToUpdate” para true.

this.setState(prevState => ({
        liveData: {
          ...prevState.liveData,
          (prevState.liveData.table.data(0).isDone): true,
        },
      }))

Esse código acima foi o que eu fiz, mas não consegui entender o motivo pelo qual não está funcionando.

html – Can’t target last of type in React Styled Component input

Hi using Styled components with React – building a split date input for day/month/year – the only change I want to make is that the width of the year input is double the length of the other two inputs, I’ve tried using :nth last-of-type etc but to no avail, I have a suspicion it is because how I’m rendering the inputs as components? Can anyone advise of a nice workaround?

Code:

const StyledInput = styled.input`

  display: block;

  height: 48px;
  width: 50px;
  margin-right: 12px;
  margin-top: 12px;
`;

  return (
    <StyledInputGroup>
      <label>
      <span>Day</span>
      <StyledInput
        type="text"
        maxLength="2"
        label="Day"
        value={day}
        onChange={(e) => setDay(e.target.value)}
      />
      </label>
      <label>
      <span>Month</span>
      <StyledInput
        type="text"
        maxLength="2"
        label="Month"
        value={month}
        onChange={(e) => setMonth(e.target.value)}
      />
      </label>
      <label>
      <span>Year</span>
      <StyledInput
        type="text"
        maxLength="4"
        value={year}
        onChange={(e) => setYear(e.target.value)}
      />
      </label>
    </StyledInputGroup>
  );

Simplified codepen:
https://jsfiddle.net/4xzn8a5q/11/

spfx React – include javascript assets in sppkg

I create my package with this command

gulp clean

gulp build –ship

gulp package-solution –ship

in my sppkg there aren’t javascript files in package, and when I deploy this in the app catalog, and use my webpart, I don’t see anything and there are a lot of error of 404

sharepoint online – How to create a wiki app using react and SPFx steps?

I have to create app wiki in sharepoint using react,it should be displayed in spfx webpart in below format.Provide me any code examples in React JS.

I would like to do a autocomplete search to find all the users and groups and permessions . I am a beginner ,provide me an example in react.thanks

React Js + AWS Cloudfront + SaaS + SSL Certificates

This is the scenario I have in mind

  • SaaS application

  • Frontend built using React Js

  • Hosted using S3 bucket + Cloudfront

  • Customer domains pointing to this application using CNAME

Questions –

  1. Can AWS certificate manager be used to issue SSL to all pointing domains ?

  2. Is S3 + Cloudfront + AWS Certificate Manager the correct choice for such an application ?

  3. What would be the cost of issuing SSL certificates in this scenarios. We are thinking of more than 100K customers

Thank you in advance for your help.

react.js – React quiz app with Redux, React Router

I was wondering what could be improved upon it. I am looking at how it’s using Redux and how it’s also using hooks and I don’t really see anything wrong with it, but I am wondering if it could be improved upon.

import React, { Component } from 'react';
import { connect } from 'react-redux';



class ResultTile extends Component {


    isCorrect(options, answers, index) {
        let i
        options.map((value, index1) => {
            if (value.isAnswer === true)
                i = index1
            return null
        })
        if (options(i).name === answers(index)) return true
        else return false
    }

    getAnswer(options) {
        let answer
        options.map((val, index) => {
            if (val.isAnswer === true) {
                answer = options(index).name
            }
            return null
        })

        return answer
    }


    render() {
        let key = 0

        return (
            this.props.questions.map((question, index) => {
                return (
                    <div
                        key={question.id - 1000}
                        className={this.isCorrect(question.options, this.props.answers, index) ? "alert alert-success mx-auto px-4 py-1 w-100 " : "alert alert-danger mx-auto px-4 py-1  w-100"}
                        role="alert">
                        <p className="font-weight-bold" > <strong> Q{question.id - 1000}.</strong> {question.name} </p>
                        <div className="container">
                            <div className="row">
                                <form className=" ">
                                    {question.options.map((option) => {
                                        return <div
                                            key={key++}
                                            className="form-check">
                                            <input
                                                className="form-check-input key"
                                                type="radio"
                                                checked={option.name === this.props.answers(index)}
                                                disabled />
                                            <label
                                                className="form-check-label">
                                                {option.name}
                                            </label>
                                        </div>
                                    })
                                    }
                                </form>
                            </div>
                        </div>

                        <div className="alert alert-dark p-1 mt-3 mb-2 w-100" role="alert">
                            Right answer is : <strong>{this.getAnswer(question.options)}</strong>
                        </div>

                    </div>
                )
            }
            )
        );
    }
}

const mapStateToProps = state => {
    return {
        answers: state.answers,
        questions: state.questions

    }
}
const mapDispatchToProps = dispatch => {
    return {
        updateBonus: () => dispatch({ type: "UPDATE_BONUS", value: 100 }),
    }
}


export default connect(mapStateToProps, mapDispatchToProps)(ResultTile);

You can check the whole app, or just this component in particular, because it’s one of the bigger components.

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123