How to declare a global variable in React?

Why don’t you try using Context? You can declare a global context variable in any of the parent components and this variable will be accessible across the component tree by this.context.varname. You only have to specify childContextTypes and getChildContext in the parent component and thereafter you can use/modify this from any component by just specifying contextTypes in the child component. However, please take … Read more

axios post request to send form data

You can post axios data by using FormData() like: And then add the fields to the form you want to send: If you are uploading images, you may want to use .append And then you can use axios post method (You can amend it accordingly) Related GitHub issue: Can’t get a .post with ‘Content-Type’: ‘multipart/form-data’ … Read more

How to resolve “Cannot use import statement outside a module” in jest

Also using Babel, Typescript and Jest. Had the same failure, driving me crazy for hours. Ended up creating a new babel.config.js file specifically for the tests. Had a large .babelrc that wasn’t getting picked up by jest no matter what i did to it. Main app still uses the .babelrc as this overrides babel.config.js files. Install jest, ts-jest and babel-jest: babel.config.js (only used by … Read more