Componets tab in react dev tools is not working properly - reactjs

I am new to react and I have just installed the React Dev Tools extension in google chrome.
I realized that the React tab in the inspect bar was replaced by Components and Profiler tabs.
But for some reason, The rendered tree is not complete in the components tab
take a look at the following pictures
This is what my app looks like in the Components tab
This is what I am expecting it to look like
And I don't know why it is showing Anonymous key = 'something' ForwardRef... Instread of showing a component over there
[![enter image description here][3]][3]
As mentioned I have installed the styled-components plugin
[3]: https://i.stack.imgur.com/j2vnd.png

Make sure you are following these:
if you are using default export of components, there is no name for the component for dev tools to use.
try:
const HelloWorld = () => {
return <h1>Hello</h1>;
};
export default HelloWorld; // Now tool has a name to work on.
For HoC, you can use 'displayName' property:
More useful ref: https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtools
React dev tools allows you to see the components that are in 'DEV' mode and not running production build.
Update after checking code:
You are using higher order components and as I mentioned earlier/above HoC needs explicit displayName
const PersonWithRadium = Radium(Person);
PersonWithRadium.displayName = "PersonWithRadium";
export default PersonWithRadium;

It seems you are really using Styled Components.
That shows to React Dev tools because you are probably not installing the debugging tools.
npm install --save-dev babel-plugin-styled-components
According to the docs it will show as styled.div if you don't install this which is pretty much similar to your problem.
More info here: https://styled-components.com/docs/tooling#better-debugging

Related

#react-google-maps/api production build is broken

React app production build stopped working. The generated chunk can not be loaded, because the output of the build generates the following line:
google.maps.LatLng(85.02070771743472,-178.41fa87a0d75)
instead of:
google.maps.LatLng(85.02070771743472, -178.48388434375)
Package versions:
react: 18.0.0
#react-google-maps/api: 2.12.0
Tried solutions, which did not help to fix the problem
Changing the version of google maps to 3.47, 3.48, 3.49
Downgrading the version of the #react-google-maps/api
Is there a solution to fix this problem? What could possibly cause this change of constant value during the production build?
Row in codebase
We managed to locate the issue, but not the root cause. We were importing a component
import { MenuItem } from 'sharedComponents/Page/UserSignedMenu'
from the file:
export const MenuItem = styled('a')`
some styling
`
The solution was to not import the component, but copy it to that file where it is used. It is a dirty fix, and violating the DRY concept, but solving the production build.
We tried to not use the styled component, just a simple div:
export const MenuItem = <div>test</div>
But did not help.

Change default import file from index.ts to index.native.ts [react-native]

I'm building a react component library (using typescript and styled-components) and I want to reuse as much as possible code between the two targets (web and native).
I have a folder called styled, and inside that folder, I have two index files: index.ts and index.native.ts.
Inside the index.ts I have: export { default as styled } from 'styled-components'; while in the index.native.ts I have export { default as styled } from 'styled-components/native';
I know react-native uses index.native.ts instead index.ts during the build process when it is available but I really need to make the IDE (vscode) to understand that, I mean, when I'm building a Button.native.ts the statement: import { styled } from '../styled' should import from the .native barrel and the ctrl + click should let us to the .native file.
I don't know if there is a configuration to change the default import file used as a barrel, I already tried to search in the typescript documentation for some react-native preset but I didn't find anything.
It is not related to TypeScript, it is an open issue on VSCode GitHub page. Still doesn't have any solution.
Even I didn't find solution on react native vscode plugin.
By my understanding you are working on RNW, so it is not a correct expectation that VSCode understand by Ctrl+CLICK your meaning is Web or Native side.When it works in development and production so forget about opening right code by click.

create-react-app / Material-UI App Styling Different on Deploy

I had a certain bug that I was unsure how to debug. The bug is that styling that I use for a create-react-app (Typescript) app through material-ui and regular CSS, shows up just fine in development but it shows differently for certain CSS properties when I deploy the app online (I've only tried Heroku and Vercel). The app doesn't show any errors or warnings in the console when I'm developing. I have no idea why it's happening and I've tried the following so far
Read through my code many times being extra careful at every step.
Open the website (development and production) in incognito mode on Chrome 85.0.4183.83 (Linux, 64 bit)
Look through the documentation for material-ui (material-ui.com) and the React docs for any lead on this
Search google for prior such issues
So far, nothing has turned up. Could someone please guide me in the right direction?
The build pack I use on Heroku after deployment is the well known one by mars and available at https://buildpack-registry.s3.amazonaws.com/buildpacks/mars/create-react-app.tgz .
For convenience, I have included my package.json here on pastebin.
Thank you so much for helping out.
============= EDIT =============
I've been experimenting with the code and it seems like the problem lies with how material-ui is compiled during build time. The problems which don't show up in development, show up in production.
For example, the biggest thing I noticed is if you mix custom style prop flags given by the material-ui components and add your own styling with className or style, during build time these latter styles are overridden partially if not completely.
So if I do
import React,
{ useRef } from "react";
import {
Button,
makeStyle,
Theme
} from "#material-ui/core";
/*
Start of functional component using memo
.
.
.
*/
const useClasses = useRef(makeStyle((theme : Theme) => { return {
buttonStyles:
{
backgroundColor: theme.palette.text.hint
}
}}));
const styles = useClasses.current();
<Button
color={"secondary"}
className={styles.buttonStyles}>
button text
</Button>
/*
.
.
.
*/
in development, the button will have the backgroundColor I give it in makeStyles, but in production that property will switch to secondary as given in the color prop which defaults to the value theme.palette.secondary.main.
And sometimes, just even using a component from material-ui without any extra config causes a problem.
I am also using code splitting with lazy and Suspense if that matters.
StackMatch can you please link your github/gitlab repo? I think I might know what the problem is but can't be certain without seeing how your dev environment is configured.

How can I use Material UI with Electron React Boilerplate?

Context
New electron user here. I just cloned and installed the recommended React + Electron repo: https://github.com/electron-react-boilerplate/electron-react-boilerplate
Now I want to use Material-UI. So I thought I just follow the instructions here:
https://material-ui.com/getting-started/installation/
After I did this, the app doesn't show me anything from Material-UI. I created a Component with a simple App Bar. But it does show nothing.
So I found out that there is another package.json in the folder /app/package.json
I cd'd into it and redid the installation. Restart the dev server but still nothing shows up (no appbar, just white screen).
Here is a screenshot:
Also according to the docs I should add a link for the roboto font to the html file. Where is this supposed to go? I put it into the only html file I found in app/app.html.
How can one set up Material-UI with Electron or rather this specific boilerplate?
I couldn't find anything up to date for this question.
I found the error. Turns out I imported MenuIcon but material doesn't export it. So when I get rid of it, the appbar renders correctly.

Office UI Fabric React Icons not showing with Gatsby

I'm trying to get Icons working with Gatsby but it they don't seem to be showing in the production build.
I am importing the icons like this
import {
initializeIcons
} from "office-ui-fabric-react"
and calling the function like this
initializeIcons()
which is all in my index.js page file. This works fine when running gatsby develop however when i run gatsby build && gatsby serve the icons show up like this.
However, when I look inside Chrome dev tools, i can see the icon fonts being downloaded.
so i am assuming it is something to do with the static render of gatsby. I started with this template https://github.com/microsoft/gatsby-starter-uifabric
Any help is appreciated.
I had the same issue. After trying a bunch of work-arounds, I ended up using office-ui-fabric-core instead.
Install the library:
npm i office-ui-fabric-core
Import the ui-fabric-core css
import "office-ui-fabric-core/dist/css/fabric.css";
example icon component:
import React from "react";
const MyIcon = ({iconName}) => <i className={`ms-Icon ms-Icon--${iconName}`} aria-hidden="true"></i>
export default MyIcon;
Example usage:
<MyIcon iconName="People" />
The answer was to use the initializeIcons(undefined, { disableWarnings: true }) method outside of the App class code, just above it will do fine.
To quote the wiki article on the use of this method
If your code is running in an environment where icons may have already been registered, you may need to disable the warnings. (By default, registering the same icon twice will ignore subsequent registrations.) To initialize icons and avoid duplication warnings, pass options into initializeIcons:
https://github.com/microsoft/fluentui/wiki/using-icons

Resources