axios post request to send form data

You can post axios data by using FormData() like: var bodyFormData = new FormData(); And then add the fields to the form you want to send: bodyFormData.append(‘userName’, ‘Fred’); If you are uploading images, you may want to use .append bodyFormData.append(‘image’, imageFile); And then you can use axios post method (You can amend it accordingly) axios({ … Read more

When to use React setState callback

Yes there is, since setState works in an asynchronous way. That means after calling setState the this.state variable is not immediately changed. so if you want to perform an action immediately after setting state on a state variable and then return a result, a callback will be useful Consider the example below …. changeTitle: function … Read more

How to fix missing dependency warning when using useEffect React Hook

If you aren’t using fetchBusinesses method anywhere apart from the effect, you could simply move it into the effect and avoid the warning useEffect(() => { const fetchBusinesses = () => { return fetch(“theURL”, {method: “GET”} ) .then(res => normalizeResponseErrors(res)) .then(res => { return res.json(); }) .then(rcvdBusinesses => { // some stuff }) .catch(err => … Read more

Why calling react setState method doesn’t mutate the state immediately?

From React’s documentation: setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value. There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains. If you want a function to be executed after … Read more

We simply cannot write “ in ReactJS?

We could pass all HTML attributes to a React component as a prop and then inside the component’s render function assign those props to the actual DOM HTML element. const Foo = ({style}) => ( <div style={style}> // assigning inline style to HTML dom element This is Foo </div> ) <Foo style={color: ‘red’} /> // … Read more

Is there a “Best Practices” on designing an application written both in React and React-Native?

Generally, you can share a lot of business logic between react native and web applications. By business logic, I basically mean the logic in your app that aren’t components. Trying to share components is pretty hard, since the base level components are different (View vs div, etc), and you generally want things structured pretty differently … Read more