reactjs

React Functional Component props does not update

这一生的挚爱 提交于 2021-02-10 16:55:35
问题 I use a functional component to display these divs. I have also another component that uses the displayCounter component and keeps track of a state. My state is a counter and I have some buttons to increase and decrease the counter. Let's say that the state is state = { counter: 0 } The div with the Example 1 does not display the changes of the counter. But the div with Example 2 works fine? So when I click to increase button div 1 always displays 0, but div 2 works fine. Can somebody explain

React testing error. Target container is not a DOM element

别来无恙 提交于 2021-02-10 16:18:37
问题 I want to write unit test for my react app. The first unit test I wrote is as follow it('renders without crashing', () => { const div = document.getElementById('root'); ReactDOM.render(<Index />, div); }); However I got the error Invariant Violation: _registerComponent(...): Target container is not a DOM element. I have to say that the application I wrote actually has no such error, if I run it with npm start This error only exists when I test my program with unit test. I'm wondering how to

React testing error. Target container is not a DOM element

混江龙づ霸主 提交于 2021-02-10 16:13:55
问题 I want to write unit test for my react app. The first unit test I wrote is as follow it('renders without crashing', () => { const div = document.getElementById('root'); ReactDOM.render(<Index />, div); }); However I got the error Invariant Violation: _registerComponent(...): Target container is not a DOM element. I have to say that the application I wrote actually has no such error, if I run it with npm start This error only exists when I test my program with unit test. I'm wondering how to

How do I connect to sql database from react?

五迷三道 提交于 2021-02-10 16:06:57
问题 I am wondering if anyone can show me how to connect my react app create with create-react-app to connect to a local mysql database. Is there any library out there that does this or do I have to start completely from scratch? 回答1: You're going to have to build a server with API routes to query the data from your database. 回答2: You need some sort of backend server script build with language such as php or nodejs that will create api endpoints to be consumed by your react scripts 来源: https:/

Calling arrow function inside react render

北城余情 提交于 2021-02-10 16:02:30
问题 I want to call function inside react render method in map function. My sample code: render() { return ( {this.state.studentLedger.map((post, i) => ( <tr key={i}> <td>{ i+1 }</td> <td>{ post.transaction_date }</td> <td>{ post.particular }</td> <td>{ post.dr }</td> <td>{ post.cr }</td> <td>{(post) => this.balance(post.dr, post.cr)} { this.state.balance }</td> </tr> ))} )} And calling this.balance() balance(dr, cr){ this.state.balance ? this.setState({balance : (this.state.balance + dr)}) : this

Uncaught TypeError: (0 , _firebase.auth) is not a function

北城以北 提交于 2021-02-10 16:00:34
问题 Trying to use Firebase authentication in a React app. I followed the instructions in the firbase docs. installed firebase with npm added a firebase.js file: import * as firebase from 'firebase' var config = { apiKey: "AIzaSyBUORmX2qG7BXFC4hqfKAq0Y6HMAsLTGbw", authDomain: "hardy-brooklyn.firebaseapp.com", databaseURL: "https://hardy-brooklyn.firebaseio.com", projectId: "hardy-brooklyn", storageBucket: "hardy-brooklyn.appspot.com", messagingSenderId: "392580429077" }; firebase.initializeApp

How do I connect to sql database from react?

不羁岁月 提交于 2021-02-10 15:59:12
问题 I am wondering if anyone can show me how to connect my react app create with create-react-app to connect to a local mysql database. Is there any library out there that does this or do I have to start completely from scratch? 回答1: You're going to have to build a server with API routes to query the data from your database. 回答2: You need some sort of backend server script build with language such as php or nodejs that will create api endpoints to be consumed by your react scripts 来源: https:/

Unable to debug test case using Jest in chrome under node devTools

泪湿孤枕 提交于 2021-02-10 15:53:41
问题 I just started using Jest. For debugging under testcase file; describe("Filter function", () => { test("it should filter by a search", () => { const input = [ { id: 1, url: "https://www.google.com" }, { id: 2, url: "https://www.yahoo.com" }, { id: 3, url: "https://www.gmail.com" } ]; const output = [{ id: 3, url: "https://www.gmail.com" }]; debugger; expect(filterByTerm(input, "gmail")).toEqual(output); debugger; expect(filterByTerm(input, "GMAIL")).toEqual(output); }); }); under Project

Successful deployment still leads to default page

吃可爱长大的小学妹 提交于 2021-02-10 15:44:05
问题 I followed the contents of three different tutorials in deploying a slightly-modified boilerplate React app to Azure App Services. The primary issue I'm having is that while all deployment pipelines and releases have been successful on Azure DevOps, navigating to the page results in the default landing page for non-deployed app services; Hey, Node developers! Your app service is up and running. Time to take the next step and deploy your code. I'll briefly describe the steps I took to get to

How to add a second header icon using headerRIght and Icon.Button

非 Y 不嫁゛ 提交于 2021-02-10 15:40:24
问题 I am trying to add a search icon next to the menu icon on my header on the right side. I have tried repeating Icon.Button but there is no change. Using React Navigation, React Native Paper, and react-native-vector-icons/Iconicons. <HomeStack.Navigator screenOptions={{ headerStyle: { backgroundColor: '#155888' }, headerTintColor: '#fff', headerTitleAlign: 'center', headerRight: () => ( <Icon.Button name='ios-menu' size={30} backgroundColor='#155888' style={{ flexDirection:"row", paddingRight: