"Objects are not valid as a React Child" on imports - javascript

import React, { Component } from 'react';
import { View, Text } from 'react-native';
import Firebase from 'firebase';
class App extends Component {
render() {
return (
<View>
<Text>App</Text>
</View>
)
}
}
export default App;
So this code is crashing because of the import Firebase from 'firebase' I used 'npm install --save firebase' and I did 'npm link firebase' and firebase is in package.json, but that import is still crashing it. Anyone know why? I saw some people just created a variable for firebase, but it does this for all imports and I also need to add a google sign in import, which also crashed my app.

Configure firebase before running the app. Check the following link to configure firebase in Android or iOS.
https://rnfirebase.io/docs/v4.2.x/installation/android
https://rnfirebase.io/docs/v4.2.x/installation/ios

Related

React router won't work for ReactJS app version 18

I just created a new ReactJS app using npx create-react-app I believe this uses React version 18 (correct me if wrong).
I'm trying to set up a router for this app but I'm not sure which one to use: react-router-dom or react-router ..or another one?
I went ahead and installed npm -i react-router-dom
Here is my app so far:
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import {} from 'react-router-dom'; //adding this line is giving me errors
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
..however adding import {} from 'react-router-dom'; is giving me compile errors like:
Compiled with problems:X
ERROR in ../node_modules/react-router-dom/dist/index.js 13:0-836
export 'AbortedDeferredError' (reexported as 'AbortedDeferredError')
was not found in 'react-router' (possible exports: Await, MemoryRouter
are there other modules I need to install? Or should I be using another router?
You cannot leave the import statement empty. You need to actually import something.
Generally, it works like this -
import {
createBrowserRouter,
RouterProvider,
} from "react-router-dom";
You can read the react-router-dom documentation to learn more about it.

How to import react in background.js of chrome extension

I want to use reactDOM for injecting content to page. So, I want to
import React from 'react';
...
import App from './src/js/App';
const root=createRoot(document.getElementById('title'));
root.render(
<App/>
);
included into my background.js but I get the following
error: SyntaxError: Cannot use import statement outside a module
Import that is causing the error:
import React from 'react'
I've done some research and tried adding type: "module" but that does not work.
What can I do to solve this?
Facing pretty similar issues atm, digging SO for a while.
Try to play around with
import React from './react.js'; // path and file extension here
or
import * as React from './react.js'; // another import option
Also, ensure you have manifest v3 in order type: "module" to work.
After many research,
I did npm run eject
here is the working react setup
https://github.com/rba1aji/chrome-extension-template-react

How to import firebase functions with npm?

Webpack is currently unable to build my project due to an error:
The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script
Imports that Webpack doesn't like most likely look like this:
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js";
import { getStorage } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-storage.js";
import { onAuthStateChanged, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-auth.js";
How can I import this with npm or any other webpack-friendly way?
Is it not possible for you to just do npm i firebase and import those functions?
Also what framework are you using? There could be a firebase library tailored specifically for your framework, like Angular.

React is not defined in Shopify module

I tried to develop my first Shopify module but when i use React i have this error in my application page on the shop.
Here my index.js
import {Page} from "#shopify/polaris";
import {RessourcePicker} from "#shopify/app-bridge-react";
class Index extends React.Component{
state = {open: false}
render() {
return (
<Page
title="Product selector"
primaryAction={{
content:'Select products',
onAction: () => this.setState({open:true})
}}
>
<RessourcePicker
ressourceType='Product'
open={this.state.open}
/>
</Page>
)
}
}
export default Index;
Shopify allows its users to determine their own React version, hence Shopify wouldn't deploy React for you and lock you on a version you might not be interested in using. You can see how Shopify defines React as a peer-dependency so the responsibility of deploying and importing React is on the user.
I think that in your case, what you might be missing is deploying React as a dependency on your package.json, and import it as follows:
import React, { Component } from "react";
I ran into the same issue with their tutorial, I went in to the package.json and changed the dependency,
"react": "^16.9.0",
"react-dom": "^16.9.0"
Then I went to my terminal and installed react again:
npm install next react react-dom
now its working fine.
You do not need to add the import.
You should use
import React from "react";
To be safe from this type of errors. If any of your previously defined imports do import React import React will not work.
But I recommend it to just be safe

404 Error when deploying React App on custom domain

It seems like I followed all the necessary in the documentation but it keeps giving a 404 Error: "There isn't a GitHub pages here" when I go into https://juliesong.me.
I got my custom domain through GoDaddy and configured the DNS like so:
Then I changed my package.json file to have
"homepage": "https://www.juliesong.me",
Added a CNAME file in the root directory containing
www.juliesong.me
And lastly went into settings in GitHub pages:
I searched my issue up and a lot of people said it might have to do with the React Router, so I edited to include a basename:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { HashRouter as Router } from "react-router-dom";
import * as serviceWorker from './serviceWorker';
const routing = (
<Router basename={process.env.PUBLIC_URL}>
<App />
</Router>
);
ReactDOM.render(routing, document.getElementById('root'));
This is my App.js:
import React, { Component } from 'react';
import {Route} from 'react-router-dom';
import { withRouter } from 'react-router'
import { GlobalStyles, } from "./util/GlobalStyles";
import Home from './containers/Home'
class App extends Component {
render() {
const home = () => <Home />
return (
<main>
<GlobalStyles />
<React.Fragment>
<Route exact path="/" component={home} />
</React.Fragment>
</main>
);
}
}
export default withRouter(App);
If anyone could help on this issue, that would be great:)
Try this one
add new file named .htaccess in your build folder
example of file
and add this code into your .htaccess file
the code
Unless you share how you are generating the build and pushing it to GitHub Pages, it is very difficult to identify the cause of this issue.
Still let me share a general way you would deploy a react app in GitHub pages.
You don't need to add basename in your router
Good thing is you are using HashRouter instead of BrowserRouter, because GitHub pages doesn't support history api like normal browser, it will look for a specific file in given path
To deploy your app you need to run the following command in same order -
npm run build # this will generate a build folder
gh-pages -d build # this will publish the build folder to GitHub pages
This is very important that you publish the build folder, because
its contains the index.html file, which GitHub will point.
You can read more about deploying react app to GitHub Pages here
React-app out of the box is client-server application, and you should compile it first to html + client side js before deploying.
There are lots of good docs: create-react-app.dev, medium.com and the shortest way here

Categories

Resources