Skip to content

Tag: reactjs

Get size of array returned by map in React render

I’m using array.map in my render method of a React component. It works but I want to know how many rows it’s rendering. I’m trying by initialising this.numRows = 0 in my constructor, then incrementing it in the map callback: But this is still showing zero. Full code here: jsfiddle.net/ra13jx…

Detect swipe left in React Native

How can I detect a left swipe on the entire screen in React Native? Would it be necessary to use PanResponder or can it be done a little more easy? Answer There is an existing component react-native-swipe-gestures for handling swipe gestures in up, down, left and right direction, see https://github.com/glepur…

React onClick and onTouchStart fired simultaneously

I have a div in my React app and I need to handle both clicks and touches. However, when I tap on a mobile, it fires both events. If I swipe on a mobile or if I click on a normal browser, it works fine, only one event is fired in each case. How can I handle this tap issue

onclick not firing in react

I am very new to react and I stuck on some idea. The problem I have is that onclick is not firing up. I am expecting when the button is clicked, alert saying hello world will be show up. However, that is not happening! Why is that? Answer You are invoking the alert() when assigning it to the onClick event

Unable to display Date in JSX in ReactJS

Following is my code which is working fine if I initialize test with a string, though if I changed it to new Date() its throwing error. Let me know what I am doing wrong as I just started with React. Code – Error – Objects are not valid as a React child (found: Fri Jul 21 2017 02:11:18 GMT+0530 (I…

Why does this JSX expression produce an odd result?

I was playing around with JSX when I found this oddity. Using the following JSX: Will produce the correct result: But I wanted to add double quotes around the quote, so I tried: Which, to my surprise, gave the correct output: I was expecting an output similar to this since it was a string literal: Why doesn&#…

Programmatically cause onBlur to trigger in react

I use onBlur to close a dropdown, but I also want to handle a click handler of an li which is render within, setState won’t work here, the behavior is broken when user try to open the dropdown again, try it here: http://jsfiddle.net/ur1rbcrz My code: Answer Your code is not working because, even though …