Echo JS 0.11.0

<~>
MaxArt 2704 days ago. link 4 points
No. Just no.
To every React developer out there: don't do this.
Don't mix content and presentation like this. We have a better tool, it's called CSS. Use it, embrace it.

This is not responsive, it's not semantic, it's hard to maintain, it's less flexible (ironic, isn't it?), it's another dependency and another layer that has to be learnt on top of all the rest. It tries to "save" you from using flexbox in CSS but it doesn't save you from actually *knowing* flexbox OR writing CSS anyway. So just use flexbox, I say!

There is no flexbox "done the React way", unless you're referring to styling your components with flexbox. This is another example of something done while asking yourself if you *could* do it but not asking if you *should* do it.

Nope, sorry, no way I'll ever use it and if I catch one of my colleagues using it I'll bite their pinky fingers.

Sorry if this appears too harsh but I really feel this is a step in the wrong direction, and I invite you to reconsider how you design your components (in React but not only).

Replies

planttheidea 2704 days ago. link 1 point
Emphatic response, appreciate the passion. I totally support your decision to not use this component, but I just wanted to clarify some things.

How is it responsive? How is this the "React way"? The answer is simply that all the responsive aspects you used to use with things like media queries in CSS now are programmatically determined and passable via props to the component. For most things this means simply moving the deterministic logic to the component itself, and for other things it allows for applications unavailable in CSS (at least until things like container queries become a real thing). I've heard this same sort of impassioned response from people the first time they heard about inline styles, and then JSS, and then styled components. It's not an invalidation of the way things have always been done ... it's just a new option.

It's goal is not to save you from flexbox; that knowledge is vital for any developer! The goal is to make satisfying the 80% use case a little more frictionless. Instead of declaring a div and adding styles for it, you just declare a FlexContainer. Or maybe you're using CSS modules and don't want to mix global with local styles but still want to keep a tiny footprint. Or maybe you're tired of fixing flexbox bugs related to inconsistent old browser implementations (https://github.com/philipwalton/flexbugs). Either way ... it's just another option.

¯\_(ツ)_/¯
jaleksic 2704 days ago. link 2 points
You could just as well prepare several atomic css classes and reuse them in a tachyons fashion. Instead of importing a component and passing various people in jsx, you would just create a div and give it several classes. You don't have to create new specific classes each time, just go `<div className='flex-container flex-v-center flex-self-v-center'>` or whatever suits you. In fact, yes one needs a framework of some kind but I think it should be based on CSS and reuse of CSS classe
jaleksic 2704 days ago. link 1 point
Haha autocorrect. Passing down people is not exactly the same as passing down props :)
MaxArt 2704 days ago. link 1 point
It's an option, alright. But not a good option, because it's a solution searching for a problem.

What should we do, create sugar libraries for every CSS spec out there? For grid (I'm sure I have already seen it)? For transforms? For animations? For sticky elements? For filters? For box shadows? For masks? For... ?
Have an idea of what I'm talking about: https://www.w3.org/Style/CSS/specs.en.html

> all the responsive aspects you used to use with things like media queries in CSS now are programmatically determined and passable via props to the component

Why would you do that? You have this in CSS in a well-known, declarative way. Media queries also listen and react to changes on the observed properties, for example when changing the orientation of the device. You're saying that this logic has to be recreated in JavaScript (in a service, presumably?) to pass down a flag from the root container. That's a little crazy for what should be a global state of the page, not to mention the additional overhead of passing yet another property, *and* more code that has to be tested.

> For most things this means simply moving the deterministic logic to the component itself

And doing the same for *all* the FlexContainer/Item around? It's the perfect way to make the UI janky, like the old days of jQuery.

> for other things it allows for applications unavailable in CSS (at least until things like container queries become a real thing)

And exactly what prevents you from doing this for any other component? What's it "allowing" exactly?

> I've heard this same sort of impassioned response from people the first time they heard about inline styles, and then JSS, and then styled components.

Definitely not the same thing. All those alternatives have been accused of breaking the separation between functionality and presentation, but it's ultimately wrong because writing styles in JS doesn't imply breaking the separation.
With your library, on the contrary, it's explicit: you have to determine and put presentational directives directly in your code, possibly at run time.

> The goal is to make satisfying the 80% use case a little more frictionless.

I appreciate the sentiment but it ultimately fails to do so. In fact, you might end up having *more* friction.
Think about this from a business point of view. It starts from the fact that another dependency, plus its tree of dependencies, *is* another point of friction.

Then comes the fact that its explicit goal is to simplify the usage of flexbox for those developers *that should already know how to use flexbox!* How can you achieve it? You have to design a *new* API that solves the usage problems of flexbox. And given that the W3C took its sweet time to design it (even though that doesn't grant anything, but well), with contributions from engineers from Google, Apple, Mozilla, Microsoft and others, I'm not saying it's impossible to create a better and *equipotent* alternative but it's definitely not an easy task.
In fact, you ended up pretty much replicating *all* of flexbox CSS properties in form of slightly differently named component attributes and values. That developers have to learn, one by one. Another point of friction.

Then it comes maintenance and real world cases. It may happen that someone has to fix a layout bug in a web app that uses flexor. That someone has never worked on the project, or maybe just marginally, and quite some time has passed. The guy finds the culprit, then can't find where to fix it because the project was supposed to used styles components, not having a clue that flexor creates its own `<style>` elements that injects in the page. Another search begins, more time lost. More friction.

> Or maybe you're tired of fixing flexbox bugs related to inconsistent old browser implementations (https://github.com/philipwalton/flexbugs).

Oh, does flexor do it out of the box? That would be remarkable, but I haven't found trace of it.
And it's actually a good thing, because several of the workarounds about flexbox bugs have limited scope and don't cover all the cases.


Your library reminds me a little of Atomic CSS, which is already a maintainability hell. If you're going to replicate all of flexbox' functionality, how is that better than writing all the properties you need in the `style` attribute?

I don't want to leave you with just a critique, so here's what I think you should do when creating a layout component: you should create something *novel*. For example, as flexbox solves a plethora of use cases and introduces a lot of complexity doing so, you can focus on a limited subset of cases and offer a new API to achieve the goal. Like this:

<PositioningContainer position="center">
  <p>I'm centered horizontally <i>and</i> vertically!</p>
</PositioningContainer>
<PositioningContainer position="bottom right">
  <img src="watermark.svg" alt="I'm a little logo!">
</PositioningContainer>

Now this is valuable because it's semantic and clear. `FlexContainer` hardly means anything, and that's not good when creating the content of the page.

So leave to CSS what CSS can do best.
planttheidea 2704 days ago. link 1 point
So maybe this simply means my README needs to be beefed up, since a lot of these arguments appear to be predicated on the fact that you NEED to provide all the flexbox properties to the container and items. Example:

> If you're going to replicate all of flexbox' functionality, how is that better than writing all the properties you need in the `style` attribute?

... you don't. Bsaed on your response, you were probably envisioning something like this:

  <FlexContainer alignItems="stretch" flexDirection="column" flexWrap="nowrap">

When in reality it is this:

  <FlexContainer column>

There are defaults for all the things, and convenience properties to simplify things, which are meant to remove a lot of boilerplate.

This is the biggest piece here; if you always had to pass down all the properties just like always having to declare your CSS, you would be spot on ... this would be useless and tiresome. But you don't; in most scenarios you are passing down one prop at most. Simply because the option exists to declare all the things doesn't mean its a requirement.

> Oh, does flexor do it out of the box? That would be remarkable

Yes, flexor tries to handle as many of the flexbugs issues as possible (and auto-prefixes for legacy support). Despite your casual dismissal of the limited scope, some users actually fall under that scope, and they like when they are catered to. You make a poignant, if not exaggerated, point when asking if we should develop a sugar abstraction for all CSS specs. Not all CSS specs require the use of multiple property declarations that have buggy and inconsistent implementations historically.

> I don't want to leave you with just a critique, so here's what I think you should do

In truth, I rather appreciate the critique ... less so on the need to instruct. Offering criticism makes it look like you have an opinion, whereas offering instruction makes it look like you think its the only one that is right. It doesn't make you sound knowledgeable (which I believe you are) ... it just makes you sound like a dick.