reactjs

keep a variable type when I get value from input onchange with React-hooks

☆樱花仙子☆ 提交于 2021-02-11 08:21:28
问题 const { useState } = React; const App = () => { const [num, setNum] = useState(0); return ( <input type="number" value={num} onChange={(e)=>setNum(parseInt(e.target.value))} /> ) } ReactDOM.render(<App />, document.getElementById('root')); <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> <div id="root" /> I want to keep num 's type as Number , not String . but

Uncaught (in promise) DOMException: Could not start video source , Uncaught Error: The error you provided does not contain a stack trace

扶醉桌前 提交于 2021-02-11 07:51:54
问题 Hey guys am trying to run a webrtc video call using react, node, socket and peerjs, if i try starting a video chat with chrome it works, if i run chrome as private and connect as second user using the video link it works but if i try connecting from another browser using same video link e.g edge or opera it doesn't work instead it console log an error.. My code import React from 'react' import io from 'socket.io-client' import Peer from 'peerjs' import './ClassWall.css' const socket = io

How to send a post request to mailchimp on express through react

∥☆過路亽.° 提交于 2021-02-11 07:21:55
问题 I am trying to send a new membership from a form in react to my express server to add to the mailchimp memberlist I am getting a cors error and I don't know if I am missing any proxys. I want a user to be able to sign up in react and then it sends it to the mailchimp database I have been able to get the members list but I am not allowed to post to it : This is my express backend : const express = require('express'); const Mailchimp = require('mailchimp-api-v3'); require('dotenv').config();

Styling custom component in GatsbyJS using styled-components

偶尔善良 提交于 2021-02-11 07:21:05
问题 I recently started using Gatsby for building my websites, previously I relied just on plain html and css, so I may be missing something really basic here... I am trying to style a custom header component that looks like this import React from "react" import MWidth from "./m-width" import logo from "../resources/images/logo.png" function Header() { return ( <> <MWidth> <div> <img src={`${logo}`}></img> </div> </MWidth> </> ) } export default Header after importing it inside the layout

Component local state not updating with react custom hooks

喜夏-厌秋 提交于 2021-02-11 07:16:04
问题 I'm just starting to use react hooks and I'm having some issues when using custom hooks. It's probably lack of understanding but here's what I'm attempting My Custom hook: import React, { useState } from "react" export const useValidateContent = initState => { const[valid, setValid] = useState(initState) const[errorMsg, setErrorMsg] = useState(null) const validate = () => { // Update component state to test setValid(false) setErrorMsg('Some error found') } return [valid, validate, errorMsg] }

React, increment global variable does not work as expected

£可爱£侵袭症+ 提交于 2021-02-11 07:14:48
问题 I tried to track the number of times react component is rendered. However, it seems that the renderCounter gets incremented by 2 each time. Why does this happen? I know it is a bad practice to use global variables, but I'm interested in the reason why this happens. https://codesandbox.io/s/rendercounter-does-not-increment-correctly-093ok?file=/src/App.js let renderCounter = 1; function App() { const [i, inc] = useReducer((_) => _ + 1, 1); // render console.log(JSON.stringify(i), "th click");

using getElementByID in React

允我心安 提交于 2021-02-11 07:12:27
问题 I am getting a "Cannot read property 'style' of null" on my getElementById('password'), but its clearly defined on the page. I'm new to react, and I'm guessing this isn't allowed or something. But I'm trying to have the password page show until, its style is changed to "none", which happens in a different component. function App() { const [loggedIn, setLoggedIn] = useState(false) if (document.getElementById('password').style.display = "block"){ setLoggedIn(false) } else { setLoggedIn(true) }

using getElementByID in React

无人久伴 提交于 2021-02-11 07:11:57
问题 I am getting a "Cannot read property 'style' of null" on my getElementById('password'), but its clearly defined on the page. I'm new to react, and I'm guessing this isn't allowed or something. But I'm trying to have the password page show until, its style is changed to "none", which happens in a different component. function App() { const [loggedIn, setLoggedIn] = useState(false) if (document.getElementById('password').style.display = "block"){ setLoggedIn(false) } else { setLoggedIn(true) }

React, increment global variable does not work as expected

 ̄綄美尐妖づ 提交于 2021-02-11 07:10:22
问题 I tried to track the number of times react component is rendered. However, it seems that the renderCounter gets incremented by 2 each time. Why does this happen? I know it is a bad practice to use global variables, but I'm interested in the reason why this happens. https://codesandbox.io/s/rendercounter-does-not-increment-correctly-093ok?file=/src/App.js let renderCounter = 1; function App() { const [i, inc] = useReducer((_) => _ + 1, 1); // render console.log(JSON.stringify(i), "th click");

React, increment global variable does not work as expected

落爺英雄遲暮 提交于 2021-02-11 07:10:18
问题 I tried to track the number of times react component is rendered. However, it seems that the renderCounter gets incremented by 2 each time. Why does this happen? I know it is a bad practice to use global variables, but I'm interested in the reason why this happens. https://codesandbox.io/s/rendercounter-does-not-increment-correctly-093ok?file=/src/App.js let renderCounter = 1; function App() { const [i, inc] = useReducer((_) => _ + 1, 1); // render console.log(JSON.stringify(i), "th click");