getElementById in React

You need to have your function in the componentDidMount lifecycle since this is the function that is called when the DOM has loaded. Make use of refs to access the DOM element <input type=”submit” className=”nameInput” id=”name” value=”cp-dev1″ onClick={this.writeData} ref = “cpDev1″/> componentDidMount: function(){ var name = React.findDOMNode(this.refs.cpDev1).value; this.someOtherFunction(name); } See this answer for more info … Read more

React component children detect if empty / null before render

Solution 1: Get the children type. It will return null if Child component returns null: const isChildNull = children => { return Boolean(children.type()=== null); }; Solution 2: Using ReactDOMServer.renderToStaticMarkup. It converts the jsx elements to string. If children returns null then renderToStaticMarkup will return an empty string: import ReactDOMServer from ‘react-dom/server’; const isChildNull = children … Read more

Can I avoid forceUpdate() when using React with Backbone?

Pete’s answer is great. Backbone models are inherently mutative, which (while not a problem in itself) means that when rerendering, you won’t have the old version of the model to compare to. This makes it harder to do intelligent optimizations by defining shouldComponentUpdate methods in key places on your components. (You also lose out on … Read more

React hook form v7 Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()

So the issue is that I think that the {…register(“name”}} line actually includes a ref property. You could console.log that out to verify; this is what I found to be true when using {…field} with the ControlledComponent. A very quick fix to get rid of the console error is to just, after the line with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)