reactjs

Why is my react component not updating with state updates?

蹲街弑〆低调 提交于 2021-02-18 10:15:26
问题 I have a map app I built that requires some map icons to appear/disappear after a button press, but I can't figure out how to set it to re-render the component when I pass in a new sports property from it's parents component : Parent loads component: <SimpleMap sports=[default value and future values go here] /> Simple map component(simplified): constructor(props) { (props); this.state = { events: [{venue: {lat: 2, lon: 1}}], sports: ["baseball", "football", "paddle", "soccer", "boxing",

React & Jest: Cannot find module from test file

半腔热情 提交于 2021-02-18 10:12:30
问题 Setting up a Jest test ('App-test.js') for a Redux action ('App.js') in a directory app/__tests__ : Here's the header of App.js: jest.unmock('../../modules/actions/App.js') import React from 'react' import ReactDOM from 'react-dom' import TestUtils from 'react-addons-test-utils' import * as App from '../../modules/actions/App.js' In app/ there is a module config.js . This is being imported where it is needed. The problem is, when I run my Jest tests, such as App-test.js, it is looking for

React-redux connect() cannot wrap component defined as a class extending React.Component

送分小仙女□ 提交于 2021-02-18 09:58:09
问题 I may be missing something, but I can't find any example where connect() wraps a component defined as a class (extending React.Component ), it always wraps components defined as a simple function. A call like this: connect(mapStateToProps, mapDispatchToProps)(HomeView) where HomeView extends React.Component , I get a Cannot call a class as a function error. Any help would be much appreciated. Edit (sorry for the ammount of code, I don't know what might be relevant): routes/Home/components

React axios calls to Express API in Heroku deployment

ぃ、小莉子 提交于 2021-02-18 08:39:18
问题 I have a React todo app I built using create-react-app and I built a simple express server to query mongoDB to get all the appointment objects. It works just as expected when I am running it on my machine. The front end spins up on localhost:3000 and the server on localhost:3001 . I use axios to make a get request to localhost:3000/api/appointments to load all the appointments into the App.js state. I uploaded it to Heroku and I got a CORS error on the request. After that, I tried to just use

https undefined in react native axios

China☆狼群 提交于 2021-02-18 07:45:08
问题 I have used axios for react native app but while implementing https.agent it shows https is undefined. How to solve this? My code const instance = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }) }); instance.get('https://example.com'); // At request level const agent = new https.Agent({ rejectUnauthorized: false }); axios.post('/practz/login', { "username" :"orgadmin1@example.com", "password":"exam", "appId":"AABBCD", "domainName":"example.com", httpsAgent: agent })

React js - Laravel 5: Using csrf-token in POST method

為{幸葍}努か 提交于 2021-02-18 07:23:26
问题 I've read some questions about Laravel's CSRF, but I still haven't found how to use it with React. My goal is to make a POST form, where I make an AJAX call. Here is an extract of my render( ) . render() { return ( <form method="post" action="logpage"> <input type="hidden" name="csrf-token" value="{{{ csrf_token() }}}" /> //I'm sure this doesn't have csrf_token. <input type="text" name ="word" value={this.state.word || ''}/> <button onClick={this.submit} className="btn btn-flat btn-brand

Calculating SVG bounding boxes with React?

强颜欢笑 提交于 2021-02-18 07:06:22
问题 I am writing a visualisation application with React generating SVG. One of the parts I need is a label - that is, text, surrounded by an enclosing box, with variable text, possibly rotated and styled. So I have a component for the NodeLabel , currently with fixed dimensions: render() { return <g> <rect className="label" x={this.props.x} y={this.props.y-10} width={20} height={40}></rect> <text className="labelText" x={this.props.x} y={this.props.y}>{this.props.children}</text> </g> } And I've

Update React state via Socket.io

自作多情 提交于 2021-02-18 06:58:36
问题 My React component uses data from socket.io as it's state. I am unsure how to just update the state when the data is updated without re-rendering the entire component. Example code. var socket = io(); var data = { components: [{key: '',name: '',markup: ''}] }; socket.on('data', function(_) { data = _; }); var Components = React.createClass({ displayName: "Components", getInitialState: function getInitialState() { return data; }, handleChange: function handleChange() { this.setState(data); },

Using Fragment to insert HTML rendered on the back end via dangerouslySetInnerHTML

拈花ヽ惹草 提交于 2021-02-18 06:34:24
问题 I used to compile and insert JSX components via <div key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> which wrapped my HTML into a <div> : <div>my html from the HTML object</div> Now react > 16.2.0 has support for Fragments and I wonder if I can use that somehow to avoid wrapping my HTML in a <div> each time I get data from the back end. Running <Fragment key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> will throw a warning Warning: Invalid prop `dangerouslySetInnerHTML`

Using Fragment to insert HTML rendered on the back end via dangerouslySetInnerHTML

筅森魡賤 提交于 2021-02-18 06:33:15
问题 I used to compile and insert JSX components via <div key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> which wrapped my HTML into a <div> : <div>my html from the HTML object</div> Now react > 16.2.0 has support for Fragments and I wonder if I can use that somehow to avoid wrapping my HTML in a <div> each time I get data from the back end. Running <Fragment key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> will throw a warning Warning: Invalid prop `dangerouslySetInnerHTML`