score:1
Accepted answer
there is need to fix this
reference, try this code:
import react from "react";
import "bootstrap/dist/css/bootstrap.min.css"
class unternehmenseinstellungen extends react.component {
constructor(props) {
super(props);
this.state = {
uname: ""
};
this.handleuname = this.handleuname.bind(this);
this.unternehmensenden = this.unternehmensenden.bind(this);
}
handleuname(e) {
this.setstate({uname: e.target.value});
}
unternehmensenden() {
if (document.getelementbyid("uname").value === "") {
alert("please fill all fields");
}
else {
var apiendpoint = "http://localhost:8080/erstelleunternehmen?uname=" + this.state.uname;
alert(apiendpoint)
}
}
render() {
return (
<div>
<div>
<input placeholder="e.g. bike company"
value={this.state.uname}
onchange={this.handleuname}
style={{...}}
type="text" id="uname" required/>
</div>
<button
style={{...}}
classname="btn btn-pill btn-dark" onclick={this.unternehmensenden}>show my state
</button>
<div>
<h3>state-test:</h3>
<p>name: {this.state.uname}</p>
</div>
</div>
);
}
}
score:1
you should bind your unternehmensenden
function in the constructor or use an arrow function
Source: stackoverflow.com
Related Query
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How can I break through React maps to display object that has two values one with an array other with string or number(result)
- React: How to build a string with state values?
- How to access URL query string values in react router with Redux
- REact js noob here, how do you change state object values while looping thru an array with their keys in it
- In React components implemented with hooks, how can the latest component state values be read from within setInterval?
- How to Update Typescript React Redux State With One or More Reducer State Values
- How to pass state values to initial values in formik in react js
- React hooks: How do I update state on a nested object with useState()?
- How to access state when component unmount with React Hooks?
- How do I use local state along with redux store state in the same react component?
- How to communicate UI state changes between React components with Redux?
- How to render a string with JSX in React
- How to build forms with material ui in react correctly
- How to correctly set initial state in React with Typescript without constructor?
- How do you update Formik initial values with the react context api values after an AJAX request?
- How to use React Hooks Context with multiple values for Providers
- How to use React Context with useState hook to share state from different components?
- How to maintain state between routes with React Router?
- How to test the state of a functional component in React with Jest (No Enzyme)
- How to recover state on back button with react
- React 16.4 enables getDerivedStateFromProps to be called from state change. How to cope with that?
- How to compare values from react redux state in hooks
- How to test react components with mobx observable state
- How to get values from react FieldArray in formik form with other fields?
- Set multiple state values with React useState hook
- ReactJS - How can I implement pagination for react with keep state when route change?
- How to optimize React components with React.memo and useCallback when callbacks are changing state in the parent
- How can ı pass function with state for react useContext
- How to change the state with React TypeScript 2.0?
More Query from same tag
- How to pass state from child component to parent in React.JS?
- Refactoring from classes to functions - ways to enhance in functions
- Redux-form how to update Material-UI v4 textField value?
- Passing data from the Redux store, as Props, to an unknown number of routes
- How to delete firebase firestore collection document if you don't know the document name?
- Where to make Ajax calls in React flux
- Pass props React Router
- React testing library's waitFor() returns null
- key is not defined React
- Smoothly animate a div as its position changes
- Using Axios in useEffect from an external file
- Generic method to render React component depends on two props
- Getting failed status while running jest test?
- React props passed to child doesn't get passed
- ReactJS: Why isn't my div showing up?
- UseEffect hook not updating state
- How to pass data from GraphQL when in a React Component
- Mocking window.get() with Jest
- Rendering ReactJS from asynchronous server side data calls
- Component only updates after two clicks React
- Redux changing my initial state
- Detect left or right part was clicked of the path element of SVG (React component)
- Unable to add Items to cart
- How I can update array field value in redux-form?
- VS2019 how to restart npm that's automatically started on local build
- renderToNodeStream [object Object] server-side-rendering
- In react, how do I do an if statement
- How to stop re-rendering a whole list of items when only one item of the list is created or updated in ReactJs React-Redux?
- OnClick on child div should not trigger parent div's onClick method for a particular child
- Calling collection from firebase comes up empty