reactjs

Sending an axios Post request with csv in its body

走远了吗. 提交于 2021-02-10 17:44:08
问题 What i am trying to achieve is send a post request from my frontend to back end using axios.This post request has a csv file in its body. Using postman : postman request My code is this: import React, { Component } from 'react'; import axios from 'axios' class SessionsUpdate extends Component { state = { selectedFile: null } handleSubmit = async () => { let formData = new FormData(); formData.append('file', this.state.selectedFile); await axios.post( 'https://localhost:8765/...', formData, {

Carousel causes screen to move to top of page on slide change

岁酱吖の 提交于 2021-02-10 17:35:48
问题 Minimum Reproducible Example on Github (The images don't show in this MRE, but that's ok and doesn't matter because the problem I'm wondering about has nothing to do with that) Problem: Every time the slide index changes, the screen scrolls to the top of the page. It happens automatically. This happens when incrementing the slide number by 1 when decrementing the slide number from 3->1 or from 2->0 But does not happen when incrementing the slide number from slide 2 to slide 3 (slides numbered

React.js - passing props to children from hoc

笑着哭i 提交于 2021-02-10 17:35:34
问题 I have been trying to pass some props from my HOC to children. the HOC wraps react router switch and route. The props are missing in the child component. I make use of React.CloneElement to add the props to the children but do not seem to work <BrowserRouter> <Layout> <React.Suspense fallback={loading()}> <Switch> <Route exact path="/" component={Login} /> <Route path="/dashboard" component={Home} /> <Route path="/tickets" component={Tickets} /> </Switch> </React.Suspense> </Layout> <

how to test async function making use of moxios?

限于喜欢 提交于 2021-02-10 17:29:49
问题 Consider the following react code. sendFormData = async formData => { try { const image = await axios.post("/api/image-upload", formData); this.props.onFileNameChange(image.data); this.setState({ uploading: false }); } catch (error) { console.log("This errors is coming from ImageUpload.js"); console.log(error); } }; Here is the test it("should set uploading back to false on file successful upload", () => { const data = "dummydata"; moxios.stubRequest("/api/image-upload", { status: 200,

how to test async function making use of moxios?

℡╲_俬逩灬. 提交于 2021-02-10 17:29:20
问题 Consider the following react code. sendFormData = async formData => { try { const image = await axios.post("/api/image-upload", formData); this.props.onFileNameChange(image.data); this.setState({ uploading: false }); } catch (error) { console.log("This errors is coming from ImageUpload.js"); console.log(error); } }; Here is the test it("should set uploading back to false on file successful upload", () => { const data = "dummydata"; moxios.stubRequest("/api/image-upload", { status: 200,

In Regular React how to dismiss mobile keyboards on submit or 'enter' key?

南楼画角 提交于 2021-02-10 17:28:45
问题 I am trying to find this answer, but all the other questions I have found are React Native. `handleEnter(e){ if(e.key == 'Enter'){ //REMOVE KEYBOARD } }` Also my input is a text search. So I want the keyboard to hide so users can see the results that come up. 回答1: e.target is the focused input or textarea where the user is writhing. When he click on Enter the focused input became unfocused and so the keyboard disappear `handleEnter(e){ if(e.key == 'Enter'){ e.target.blur(); } }` 来源: https:/

React - how do I unit test an API call in Jest?

安稳与你 提交于 2021-02-10 17:26:42
问题 I have a bunch of API calls that I would like to unit test. As far as I know, unit testing API calls doesn't involve actually making those API calls. As far as I know you would simulate responses of those API calls and then test on the DOM changes however I'm currently struggling to do this. I have the following code: App.js function App() { const [text, setText] = useState(""); function getApiData() { fetch('/api') .then(res => res.json()) .then((result) => { console.log(JSON.stringify

In Regular React how to dismiss mobile keyboards on submit or 'enter' key?

微笑、不失礼 提交于 2021-02-10 17:26:14
问题 I am trying to find this answer, but all the other questions I have found are React Native. `handleEnter(e){ if(e.key == 'Enter'){ //REMOVE KEYBOARD } }` Also my input is a text search. So I want the keyboard to hide so users can see the results that come up. 回答1: e.target is the focused input or textarea where the user is writhing. When he click on Enter the focused input became unfocused and so the keyboard disappear `handleEnter(e){ if(e.key == 'Enter'){ e.target.blur(); } }` 来源: https:/

React - how do I unit test an API call in Jest?

人盡茶涼 提交于 2021-02-10 17:23:11
问题 I have a bunch of API calls that I would like to unit test. As far as I know, unit testing API calls doesn't involve actually making those API calls. As far as I know you would simulate responses of those API calls and then test on the DOM changes however I'm currently struggling to do this. I have the following code: App.js function App() { const [text, setText] = useState(""); function getApiData() { fetch('/api') .then(res => res.json()) .then((result) => { console.log(JSON.stringify

React - how do I unit test an API call in Jest?

那年仲夏 提交于 2021-02-10 17:19:50
问题 I have a bunch of API calls that I would like to unit test. As far as I know, unit testing API calls doesn't involve actually making those API calls. As far as I know you would simulate responses of those API calls and then test on the DOM changes however I'm currently struggling to do this. I have the following code: App.js function App() { const [text, setText] = useState(""); function getApiData() { fetch('/api') .then(res => res.json()) .then((result) => { console.log(JSON.stringify