reactjs

Using computed value for sub key with React setState

时光怂恿深爱的人放手 提交于 2021-02-19 06:38:04
问题 I would like to be able to use computed values for sub keys when updating state in React. I understand how to use computed values in straightforward settings like this: this.setState({ [name]: value }); But I am having trouble getting key-value computation to work for a situation like this: constructor(props) { super(props); this.state = { foo: { a: 1, b: 2 } }; } const keyToChange = 'a'; const value = 3; this.setState({ foo[keyToChange]: value }); How can I make something that works like

TypeError:Cannot read property 'map' of undefined in reactjs

房东的猫 提交于 2021-02-19 06:16:58
问题 I'm using React.js. I want to use the data I have captured in Mock Api in product detail in an e-commerce site, but I get the following error. My goal here is to extract and print data from Mock API in ProductDetail. ProducDetail.js; const ProductDetail = (props) => { const { name, description, price } = props; const axios = require('axios'); const [dress, setDress] = useState([]); useEffect(() => { axios .get(`{url}`) .then(function (response) { setDress(response.data.dress); }) .catch

TypeError:Cannot read property 'map' of undefined in reactjs

末鹿安然 提交于 2021-02-19 06:16:27
问题 I'm using React.js. I want to use the data I have captured in Mock Api in product detail in an e-commerce site, but I get the following error. My goal here is to extract and print data from Mock API in ProductDetail. ProducDetail.js; const ProductDetail = (props) => { const { name, description, price } = props; const axios = require('axios'); const [dress, setDress] = useState([]); useEffect(() => { axios .get(`{url}`) .then(function (response) { setDress(response.data.dress); }) .catch

React Native XHR multipart/form-data send data as [object Object]

删除回忆录丶 提交于 2021-02-19 06:12:46
问题 I'm trying to send a multipart/form-data from React Native (Running on Simulator) to backend server using XHR with the following code let xhr = new XMLHttpRequest(); xhr.open('POST', 'http://....url....'); let formdata = new FormData(); formdata.append('title','This is awesome'); xhr.send(formdata); However in console log the Request Payload are shown as [object Object] So I decided to take the same code and put it in an HTML file and run from Chrome browser and Request Payload from console

React Native XHR multipart/form-data send data as [object Object]

我们两清 提交于 2021-02-19 06:10:55
问题 I'm trying to send a multipart/form-data from React Native (Running on Simulator) to backend server using XHR with the following code let xhr = new XMLHttpRequest(); xhr.open('POST', 'http://....url....'); let formdata = new FormData(); formdata.append('title','This is awesome'); xhr.send(formdata); However in console log the Request Payload are shown as [object Object] So I decided to take the same code and put it in an HTML file and run from Chrome browser and Request Payload from console

Error while configuring CSS modules with webpack

随声附和 提交于 2021-02-19 06:02:09
问题 I am trying to configure CSS modules with webpack but I get an error. I have checked the other answers here on stackoverflow but none of the solutions have made it work for me so far. I have added the loader as the docs suggest but it still shows an error. This is my webpack.configuration.js file. const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.join(__dirname, '/dist'), filename: 'index

React Router display one component for all routes ( a header)

浪尽此生 提交于 2021-02-19 05:43:05
问题 Have a question regarding react router. I have a header item that I would like to display for all routes. And of course, I want this to be part of the so that the user can click items from a nav. Currently I have my <Header /> outside of my <Router> and I guess this isn´t working since my router then don't know to re-render? import { BrowserRouter as Router, Route, Switch } from 'react-router-dom' <div> <Header /> <Router> <Switch> <Route exact path="/" component={Posts} /> <Route exact path=

Dynamic HTML lang property in statically generated Next.js pages

拈花ヽ惹草 提交于 2021-02-19 05:39:46
问题 I'm working on a multilange static landing page in a Next.Js project. My goal is to have the following structure: / -> English Home page /de -> German Home page /it -> Italian Home page I'm building it in the following way: pages/index.js export default function Home() { return <div>English Homepage</div> } pages/de.js export default function Home() { return <div>German page</div> } In order to make the website accessible, I would like to set html lang accordingly. pages/_document.js class

React Not Updating Render After SetState

匆匆过客 提交于 2021-02-19 05:38:40
问题 I've played around with the code for a while now. I'm grabbing data from Firebase and populating a list of objects from that data onto this UserProfile page. I just want it to work so that when I go on the profile page, a list of their items is listed there. The problem is that with this version of the code I have to click on the profile link twice for the items to show up, but the display name shows up fine. I know setState is asynchronous. I've tried setting the state in a callback in

Improve axios get download speed

女生的网名这么多〃 提交于 2021-02-19 05:38:06
问题 I am using axios to download a file (~100MB) from an Azure Storage Blob. axios({ method: 'get', url: uri, onDownloadProgress: (progressEvent) => { console.log("Loaded: " + ((progressEvent.loaded / progressEvent.total) * 100) + "%"); }, responseType: 'arraybuffer' }).then({}) My problem is that it is taking quite a while to actually download the file (~10 minutes). I was previously using fetch() which was slower than this even (~15-20 minutes). Are there any recommendations you guys have on