React Error: Cannot update during an existing state transition [closed] - reactjs

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have the following click handler:
<Select
name="batchCompChooser"
value={this.state.batchCompId}
options={batchCompItems}
clearable={false}
onChange={this.handleBatchCompChange()}
/>
However, I get the following error from the onChange line:
BatchComponentChooser.js?0aaf:54 Uncaught TypeError: Cannot read property 'value' of undefined
How do I fix this?

If you have an event handlers, such as onClick, it is easy to accidentally do this:
onClick={this.someFunc()}
REMOVE THE parens ()
That will actually invoke the function immediately on render.
Instead you want to pass a reference to a function like this:
onClick={this.someFunc}
So in my case it should look like this:
<a onClick={this.doSomething}>Do something link</a>
If you need to pass parameters, you can do it like this with the arrow function:
<a onClick={() =>this.doSomething(true)}>Do something link</a>
Specifically in the example above the onChange should have the trailing parens removed, it should be changed to:
<Select
name="batchCompChooser"
value={this.state.batchCompId}
options={batchCompItems}
clearable={false}
onChange={this.handleBatchCompChange}
/>
Hope that helps someone out there...

Related

React Component getting displayed and disappearing immediately [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I'm learning React and as part of that I have tried some code for making a notebook kind of app where I get to add notes and then they are displayed dynamically
When I'm trying to add a note, the new react component(note) is getting displayed but immediately getting disappeared. As if the entire browser is refreshed. Attaching my code. This is my first time asking the question so not even sure how of it was understandable.
https://codesandbox.io/s/keeper-part-3-starting-forked-0mf1cs
For most of the modern browsers the default type of button tag is submit (https://stackoverflow.com/a/31644856/7399478). So, the form is submitted when you click the button and the page is refreshed after submit.
You need to change add type="button" to your button tag in your CreateArea.jsx component in order to prevent submitting the form like:
<button
type="button"
onClick={() => {
props.onAdd(note);
}}
>
Add
</button>
You can take a look at this forked sandbox for the live working example.

React Js Date Range Picker [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am using react-day-picker library to for date rage picker react-day-picker library url but I want to show this calendar on my button click event. How to achive this.
how about setting a flag before rendering the component by using the state?
ex.
a button click can call renderCalendar method
renderCalendar(){
this.setState({showCalendar:true})
}
and instead of doing :
<DayPicker numberOfMonths={2} />
wrap it inside a conditional statement
{ this.state.showCalendar ?
//show the calendar
<DayPicker numberOfMonths={2} /> :
//Do not show the calendar
null
}

Attribute tag will not work in css as one of my selectors [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is there any reason that this attribute tag a[h2]{color:orange;} wont work in css? I Cant seem to get the attribute tag to work for any elements.
a[h2] {
color:orange;
}
Means that all <a> tags that have an attribute called h2 will be coloured orange; i.e. <a h2="whatever">hello, world!</a>.
This is probably not what you want, both because this would be invalid HTML (h2 is not an attribute of <a>, and custom attributes are only allowed if they start with data-), but also because I am assuming that you want to target <h2> tags that are inside of your <a> tags.
To that, use the following code:
a h2 {
color:orange;
}
That will colour all <h2> tags inside of <a> tags orange.
Read more about CSS Selectors here.
Did you make a reference in the html page to your stylesheet?
<link rel="stylesheet" type="text/css" href="theme.css">
If this is done, check whether the element has an h2 attribute. Something like <a h2="value">

React inline styling with multiple inputs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
How would we implement something like "padding: 0 10px" for inline styling on a React element? It throws an error if I give the padding or margin properties the shortcut syntax, so I have to explicitly declare paddingTop, paddingRight, etc. I don't see anything on the React docs to address this, so I'm wondering if it's possible to use the shortcut in React?
It is possible you just probably have a typo or accidentally wrote it wrong. The syntax to apply an inline style follows this pattern.
{{property: 'value'}}
you can't add a semi colon in the value for a property.
inline styles are denoted as an object for react. and the syntax to apply a property or read something as javascript in the react render method is also denoted with curly braces.
So to apply that to your specific question, you would just do this.
<div style={{margin: '0px 10px'}} />
if you are using a style variable that is defined before the return of your render function you can use it like so.
const divStyles = {
margin: '0px 10px'
}
// ... in the render return
<div style={divStyles} />
Sample Fiddle with shortcut padding and margin used

set conditional focus on some field in angularjs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hello all fellow engineers , i have seen so many questions and well suggesting answers regarding setting focus on some input field but i didn't found anything which will fulfill my requirements , now my question is if we have multiple input fields and we don't know where to set the focus , and on some condition basis i want to set focus on some field back from controller, is there anything like "document.getElementbyId("").focus" as in javascript with "ng-model" or something , any help will be appreciated thanks
This directive will cause an element to receive focus when the passed in expression is truthy.
Live Demo
Usage:
<!-- set `$scope.foo` to a truthy value when this input should be focused -->
<input type="text" focus-when="foo">
<button ng-click="foo = true">Focus input.</button>
The directive:
.directive('focusWhen', function() {
return {
scope: {
focusWhen: '='
},
link: function($scope, $element) {
$scope.$watch('focusWhen', function(shouldFocus) {
if (shouldFocus) {
$element[0].focus();
}
});
}
};
})

Resources