reactjs

React State is not updated with socket.io

本小妞迷上赌 提交于 2021-02-11 12:39:11
问题 When page loaded first time, I need to get all information, that is why I am calling a fetch request and set results into State [singleCall function doing that work] Along with that, I am connecting websocket using socket.io and listening to two events (odds_insert_one_two, odds_update_one_two), When I got notify event, I have to check with previous state and modify some content and update the state without calling again fetch request. But that previous state is still [] (Initial). How to get

React : TypeError: Cannot read property 'Item' of undefined

空扰寡人 提交于 2021-02-11 12:39:08
问题 I want to access the value of state/property in new state prop. Actually I have already state property where I am storing value of Item=5 and I create UrlParam Where I am storing URL but I need Item numeric value in URL property. I am new to React , Somebody please help me how to do this ? When I getting Error TypeError: Cannot read property 'Item' of undefined , Could someone please help me ? Code this.state={ Item : 5, skip:0, urlParams:`http://localhost:8001/meetups?filter[limit]=${(this

Can I host my React/redux (client and api server) project on github pages?

◇◆丶佛笑我妖孽 提交于 2021-02-11 12:38:21
问题 I know I can host my react/redux app on github pages by just serving the bundle.js and index.html, but can I also host an api server for the backend that is say username.github.io/api? The server uses node.js/express and they are separate directories. Also, can I make the server repository private and still host it on /api? I looked through the documentation on github pages about creating "projects" but it doesn't make much since to me. If anyone can shed some light on this, it would be must

How to change a text inside an element, corresponding to an onClick event in ReactJs?

别来无恙 提交于 2021-02-11 12:38:02
问题 I am displaying two divisions corresponding, to two button's onClick event: class Home extends React.Component { constructor() { super(); this.state = { isShowaMale: false }; this.toggleShowMale = this.toggleShowMale.bind(this); } toggleShowMale(show) { this.setState({ isShowaMale:show }); } render() { const { isShowaMale } = this.state; return ( <div className="container py-5"> <div className="row"> <button className="btn col-6 bg-transparent col-12 col-sm-6" onClick={() => this

svg with mask not seen on chrome

这一生的挚爱 提交于 2021-02-11 12:36:49
问题 I'm trying to mask with some svg path that is created dynamically with React. The problem is that the resulted html code doesn't render properly on Chrome and Safari immediately. Correct results appear on browser window resize or check/uncheck of a style property from inspector. I feel like the problem in one of the -webkit properties but can't define which. Tried -webkit-mask , but it didn't give any results. Here's the html structure that should render right away: <div> <div id="type-1

Failed to parse multipart servlet request from express js server to backend java endpoint

孤者浪人 提交于 2021-02-11 12:36:49
问题 This is an extension to an issue with the front end(react->express file upload). The back end API endpoint works fine from Postman but fails from the front end side Unable to send the multi part form data from React to Express Js correctly Any thoughts on this? Browser network tab - Headers Request URL: http://localhost:8080/sendMyUserData Referrer Policy: strict-origin-when-cross-origin Accept: application/json, text/plain, */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0

Error with && logical operator jsx and typescript

只愿长相守 提交于 2021-02-11 12:36:35
问题 I'm fair new to typescript and I was wondering why this fails import {CircularProgress} from 'components/shared/material' import React from 'react' import loadingStyles from './styles' const Loading = ({active}: {active: boolean}) => { const classes = loadingStyles({active, fadeSpeed: 1}) return ( active && ( <div className={classes.overlay}> <CircularProgress /> </div> ) ) } export default Loading And when I try to use it in another component I get this message: Loading' cannot be used as a

Is it possible to change route on scroll?

爷,独闯天下 提交于 2021-02-11 12:36:12
问题 I want to load multiple components on a single page and have different routes for all of them. For example i hit a route /article/1 and it loads a component, after scrolling through completely through that article i want the route to change to /article/2 and the corresponding article to load. I am using react and react router, basically i want 4 (article/3 , article/4) articles on a page and all these should be scrollable with the route changing as i scroll onto a particular article. How can

async await not behaving as expected in reactjs

[亡魂溺海] 提交于 2021-02-11 12:35:32
问题 I have const [data, setData] = useState([]); const getData = async () => { const { data } = await axios.get('/getData'); setData(data.payload); }; and a button to call handleDelete from the backend const handleDelete = async () => { checked.forEach(async (element) => { await axios.delete('/deleteData', { data: { data: element }, }); }); await getData(); console.log(data); }; The data is deleted from the backend, I have components that depends on data in React and for some reason, data is not

Manipulate the DOM using jQuery, without changing the react code

泪湿孤枕 提交于 2021-02-11 12:33:52
问题 Let's say I want to develop a third party plugin, like a chrome extension. So I will have absolutely no privilege to change the javascript code of the page. All I can do is add things external to the page. So I would use jQuery to manipulate the DOM. But if the page is rendered by react, what I did to the DOM would be erased in the react lifecycle. I see some tutorials teaching how to integrate jQuery in to a react app. But this is not what I need. Is there any way to manipulate the DOM