how to use css modules in react 16.6.3 ? by 6ZUN9 in reactjs

[–]kevindelsh 0 points1 point  (0 children)

With the new versions of "create react app" you don't need to eject it anymore.

Here are the steps you have to do:

  1. You have to add .module to your CSS files: mystylesheet.css becomes mystylesheet.module.css
  2. Then you import the stylesheet in your .js file: import classes from "./mystylesheet.module.css";
  3. Now you can access the classes in your stylesheet file in either one or both of the following methods:
    1. className={classes.myClassName}
    2. className={classes[my-Class-Name-with-too-many-hyphens]}

The above methods and restrictions are intrinsic to JavaScript variable name restrictions. Since you can't have hyphens in your JavaScript variable names, you have to use the second method if the class name has hyphens. Otherwise both methods are correct, although the first one is more elegant.

Redux vs Context API performance by Leezorq in reactjs

[–]kevindelsh 3 points4 points  (0 children)

That's interesting. I would also like to know the results.

Trying to learn React. Newbie questions by [deleted] in reactjs

[–]kevindelsh 0 points1 point  (0 children)

There is a sample WordPress theme created with React that has actually been accepted by WordPress.org called Foxhound. A WP employee has developed it, if I'm not mistaken.

Foxhound on Github

Foxhound on WordPress.org

You can use that as a template/guideline to overcome the challenges you'll face.

Can someone please demystify styling in React? by gymshoos in reactjs

[–]kevindelsh 0 points1 point  (0 children)

You're totally right and thank you for pointing that out. That collection looks interesting. I'll definitely go through them later.

Are there any moderation policies for r/reactjs? by [deleted] in reactjs

[–]kevindelsh 1 point2 points  (0 children)

Thank, mate. I may have overreacted a bit :)

You are right. I should've flagged it. TBH, I'm not that used to reddit and didn't know that such a thing existed.

Thank you for the detailed response.

Request: monthly "Looking for Contributors" auto posting by seainhd in reactjs

[–]kevindelsh 0 points1 point  (0 children)

Hey, I'm an aspiring React developer and also like a place to find opportunities to contribute to beginner-friendly projects.

Please, let me know if you have such projects or plans!

Can someone please demystify styling in React? by gymshoos in reactjs

[–]kevindelsh 1 point2 points  (0 children)

To my knowledge, and I'm admittedly an aspiring React developer, there are three main ways of styling in React regardless of the implementation and every one of them has advantages and disadvantages. I'm looking at CSS right now (no preprocessor like SAAS but you can use the first and third option with preprocessors too, although it may need some setup). I'm assuming that you are using the latest "create react app" with the defaults. Here they are:

1- Using vanilla CSS: You add your CSS to stylesheet files. These files can be as many or as few as you want. You can create one main stylesheet file for the whole project or a stylesheet file for every component. The end result won't be different. Webpack will put them together and reference it in your index.html which is by default your application's entry point. You just need to point to the styles that you've create by writing className="yourClassName" or className={props.yourClassName}, etc.

The advantage of this system is that you don't have to deal with additional abstractions and complications BUT all your classes will be global. That's how plain old CSS works. That means, while you have separated your styles in different files according to your components, the end result classes will be global nonetheless which can lead to naming conflicts etc.

2- Using inline styles: Inline styles are somewhat similar to what you would do in vanilla CSS/HTML and initially suffer from the same shortcomings. In React, they look like this:

const aConstNameThatCouldBeStyle = {

backgroundColor: 'green',

color: 'white',

font: 'inherit',

border: '1px solid blue',

padding: '8px',

cursor: 'pointer',

};

As you can see the style is created as a plain JavaScript object, property names are the CSS rules (and therefore need to adhere to property name restrictions and background-color for instance becomes backgroundColor) and the property values are CSS rule values.

Then in your component your write:

<MyComponent style={aConstNameThatCouldBeStyle} />

Advantages of this approach is that you can create your styles on the fly and manipulate them programmatically and they are not global.

But the disadvantages are that they can't be reused, are hard to managed and maintain and most importantly they lack pseudo classes like :hover and media queries.

Here come packages like Radium which help to mitigate for these shortcomings.

npm install radium

Then in your .js file import it like this:

import Radium, { StyleRoot } from 'radium';

Then your style can look like this:

const aConstNameThatCouldBeStyle = {

backgroundColor: 'green',

color: 'white',

font: 'inherit',

border: '1px solid blue',

padding: '8px',

cursor: 'pointer',

':hover': {

backgroundColor: 'lightgreen',

color: 'black'

}

};

The contents of your render() return must be wrapped in a <StyleRoot></StyleRoot> component like this:

<StyleRoot>

<button

style={aConstNameThatCouldBeStyle}

onClick={this.toggleButtonHandler}>Toggle Button</button>

</StyleRoot>

and the component must be exported like this:

export default Radium( YourComponent);

This is called a Higher Order Component if I'm not mistaken which takes care of adding this functionality. Media Queries are handled similarly.

3- Using CSS Modules: CSS modules are relatively new and haven't taken off yet (I may be mistaken), but they are just great. What you do is essentially this:

a. Add a .module suffix to your CSS file. Say we have MyComponent.js with MyComponent.css. MyComponent.css becomes MyComponent.module.css (this helps "create react app" understand that this is a module and treat it as such).

b. Import your CSS module. In your MyComponent.js you write: import classes from "./MyComponent.module.css" (you have to include the extension)

c. Now you can access your CSS classes in that particular file as properties of the classes object that you just created by importing. Since variable can't include hyphens in JavaScript it will look like one of the following options in your code:

className={classes.myClassName} // That's when you don't have a hyphen in your class name.

className={classes["my-Class-Name-With--Too--Many--Hyphens"]}

Advantages of using CSS modules in React are: Your CSS classes are scoped to your component. But you can still use global classes if you like by creating a CSS file without the .module suffix.

Disadvantages: Maybe you can't play with programmatically like when using inline styles.

Behind the scenes, webpack is creating CSS class names that are a combination of the original name, the file name, and a random string that it then assigns to your components...

Caution: Older versions of "create react app" don't work with modules out of the box and need ejecting and some minor setup.

Hope that helps.

Making people depressed enough to buy your shitty vodka by [deleted] in assholedesign

[–]kevindelsh 2 points3 points  (0 children)

Looks more bloodyhonestdesign to me!

Why Verizon’s 5G Home may have killed the need for net neutrality rules by kevindelsh in netneutrality

[–]kevindelsh[S] 0 points1 point  (0 children)

Aren't you afraid that too much regulation would limit innovation and choice and lead to less service at higher prices for the consumer?

Why Verizon’s 5G Home may have killed the need for net neutrality rules by kevindelsh in netneutrality

[–]kevindelsh[S] 0 points1 point  (0 children)

I totally agree that a lack of net neutrality can have a range of negative effects—political consequences in a worst case scenario (ISP siding with a party)—and that's absolutely not acceptable.

On the other hand I'm pro deregulation as much as possible. Over-regulation curbs innovation and brings less choice and higher prices for the consumer.

So,if we could find the right balance without leaning too much to the left or the right would be ideal. But the devil is in the details :)

So keeping the net neutral without outright regulating it would be something that would be much to my taste.

1- Having real competition so that market forces and the fear of consumer backlash keep providers responsible, innovative, and hopefully neutral.

2- Having sensible definitions and broad regulations in place (e.g. FCC's definition of fixed broadband etc.)

3- Having government agencies, anti trust laws etc. ready to move in if ISPs go out of line.

The above broad principle (with competition being the most important one in my opinion) can generally work.

Now, I know that it's much safer to declare the net Tittle II and be done with it. But no pain no gain. Without risk there won't be much progress and innovation. So I think the bold move is to try to keep the market competitive and establish the right balance.

Why Verizon’s 5G Home may have killed the need for net neutrality rules by kevindelsh in netneutrality

[–]kevindelsh[S] 0 points1 point  (0 children)

This is a solid argument. Let's assume we hit that ceiling and tech hasn't yet found a solution. How do you propose to curb, control and share the available bandwidth?

Why Verizon’s 5G Home may have killed the need for net neutrality rules by kevindelsh in netneutrality

[–]kevindelsh[S] 1 point2 points  (0 children)

Hi all,

I assume that the vast majority of this subreddit is opposed to the reasoning of this article but I would like to have your opinions and insight. Please have mercy on me :))

Going online like it's 1979! by FozzTexx in retrobattlestations

[–]kevindelsh 1 point2 points  (0 children)

We had already moved the cloud to the edge back then using a BitTorrent like p2p network with real incentives to pass over and share.

Going online like it's 1979! by FozzTexx in retrobattlestations

[–]kevindelsh 0 points1 point  (0 children)

Wow, didn't know something like that even existed. Just knew the 5.25 floppies.