Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ddiddles
Oct 21, 2008

Roses are red, violets are blue, I'm a schizophrenic and so am I

Pollyanna posted:

I'm tempted to just roll my eyes and say "whatever" at the people who want natural language forms exactly like https://www.ladderlife.com/get-quote and https://havenlife.com/term-life-insurance-quote.html and are unquestioningly pushing for us copying them down to the letter. I'm not a UX/UI designer, but I still feel like being THAT restrictive on things like date input might just annoy users. But, I'm also getting pushback on a PM over this (I don't know who else is in charge of design, user acceptance, etc. for this subject) who is really in the tank for it, so v:goleft:v It'd be less effort and headache for me to just go with it, even if users end up disliking it.


If I came across a site that used a form like that, I'd roll my eyes so hard the world would end.

Adbot
ADBOT LOVES YOU

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

ddiddles posted:

If I came across a site that used a form like that, I'd roll my eyes so hard the world would end.

Essentially those forms are for branding, not ux. they're supposed to be friendly conversations with your new buddy ol' pals the insurance company. Of course your buddy ol' pal the insurance company is anything but, which is why they make these forms.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



I don't think it's that bad really. They both provide a clear visual partition between text and input, there are placeholders so you know what kind of data it expects, and the input is in full english sentences so for more domain-specific input you can get a clearer picture of what it means from the sentence it is contained within (also if you do it right then it might be helpful for ESL speakers by being given more context instead of one word, if you phrase it the right way).

edit: I'm also not sure what's bad about having a restrictive date format.

piratepilates fucked around with this message at 00:42 on Jan 31, 2017

Plavski
Feb 1, 2006

I could be a revolutionary
I read this article today about Angular's new versioning. Seems quite loopy to me: https://ilikekillnerds.com/2016/12/angular-2-team/

geeves
Sep 16, 2004

Plavski posted:

I read this article today about Angular's new versioning. Seems quite loopy to me: https://ilikekillnerds.com/2016/12/angular-2-team/

I don't think It's too bad really: http://angularjs.blogspot.com/

quote:

AngularJS for any 1.x release, and Angular for any 2+ release.

"Angular 1.x" has been AngularJS since the beginning. Genpop as always trimmed out JS out of convenience. But AngularJS is the actual product name. The new product is just Angular, but they had to keep 2 in the name to differentiate. Considering 1.x vs. 2.x are in no way compatible it really is a completely separate product. They could have rebranded, perhaps even should have, but that's its own can of worms.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Anyone here done much with GraphQL? I haven't really paid much attention to it since it came out, since I mostly build my backend projects with Python...but it looks like there a nice library for it now.

Just from reading a bit this afternoon it looks like a nice alternative to REST APIs.

Tivac
Feb 18, 2003

No matter how things may seem to change, never forget who you are

Thermopyle posted:

Anyone here done much with GraphQL? I haven't really paid much attention to it since it came out, since I mostly build my backend projects with Python...but it looks like there a nice library for it now.

Just from reading a bit this afternoon it looks like a nice alternative to REST APIs.

I really like Netflix's falcor lib for that sort of stuff. I found the GraphQL syntax really annoying.

porksmash
Sep 30, 2008
I like graphql's syntax but it gets annoying when you use the Relay spec with all these nodes and edges. I just want articles and authors.

I played around with it on a Django backend, and it seemed to work well except for the ability to optimize queries with select_related and prefetch_related to avoid the n+1 query problem

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Munkeymon posted:

JFC what a poo poo stupid design but hey that's Google and therefore Android for you.

It's the same in Windows and in one of the more popular Bootstrap Datepicker libraries as well. It's a pretty common UI feature to click/tap on "thing you want to change". I agree the discoverability is poor but turning it into some weird anti-Google/Android thing is a little weird since it's not specifically a Google/Android thing by any stretch.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



The Wizard of Poz posted:

It's the same in Windows and in one of the more popular Bootstrap Datepicker libraries as well. It's a pretty common UI feature to click/tap on "thing you want to change". I agree the discoverability is poor but turning it into some weird anti-Google/Android thing is a little weird since it's not specifically a Google/Android thing by any stretch.

I'm not aware of a Windows-universal datepicker? IIRC the Windows Phone one looks a lot like the iOS one, both of which seem fine, as did the old Android one - I forget what they called the black with neon blue lines design.

Also, there are two year fields in that control but only one of them changes when you jog the month and it's not the one you can tap to change the year but rather the one above the much bigger 'reset to today' button that's not at all visually distinct from that reset button, so, yeah, that design is bad. I might be too quick to blame all of Google, but I think their reputation deserved and I'm glad it looks like they're at least trying to turn it around. This was a backslide, though, and a really frustrating one when you have to test a form that's supposed to validate that the user is over 18 :argh:

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.

Munkeymon posted:

Using an actual type="date" to enter a birthday is currently a bad idea because the Android date control only lets you jog one month at a time, defaults to the current date and is really easy to set to the current date (accidentally press any of the green part at the top of the overlay in the image below!), so any adult is going to have to tap a stupid button 200+ times to get anywhere near their birthday.



Why don't you take the spinner approach?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Mindisgone posted:

Why don't you take the spinner approach?



Because there's one built in and rolling my own is usually worse in that case.

Kekekela
Oct 28, 2004
Goons please share your experiences with Jest. I'm thinking of putting some time into it.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!
gently caress this field.
I have to relean everything I learned about Webpack, which wasn't much, becuase of Webpack 2.
So now I'm trying to do the most basic of things, but of course, tutorials are either "hello world" or "here's a giant multi-page website using 17 other technologies". All I want is it to compiles SASS, which of course it's ignoring. I was following this, until I actually tried to follow it. webpack --watch works, but when I try npm run build it has a bunch of errors*. Why? because gently caress me, I guess? I'm sure by the time I figure out where I went wrong in literally copy/pasting a tutorial Webapack 3 4 17 will be out, and web dev will 100% be archaic terminal commands you just have to ~know~.

To be fair, the tutorial is 4 days old, so I'm sure it's completely out of date and useless now.



*
code:
ERROR in bundle.js from UglifyJs
SyntaxError: Unexpected character '`' [bundle.js:74,17]

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\                                  node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! webpack2-demo@1.0.0 build: `webpack -p`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the webpack2-demo@1.0.0 build script 'webpack -p'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the webpack2-demo package                                  ,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack -p
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs webpack2-demo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls webpack2-demo
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:

ddiddles
Oct 21, 2008

Roses are red, violets are blue, I'm a schizophrenic and so am I
Are you writing ES6?

The first two lines of your error message tell you what messed up. It came across a back tick character it didn't like on line 74, which is used for template strings in ES6.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!

ddiddles posted:

Are you writing ES6?

The first two lines of your error message tell you what messed up. It came across a back tick character it didn't like on line 74, which is used for template strings in ES6.

I dunno, am I? I only say it that way because I'm just following the linked tutorial
I see ` in app.js
code:
const root = document.querySelector('#root')
root.innerHTML = `<p>Hello webpack.</p>`
But the tutorial said to add babel-loader with an es2015 option. Shouldn't that compile it so it works, or am I misunderstanding what that does?

If the back-tick is what it is complaining about, why did webpack --watch work but npm run build not work?
Also, more rhetorical: Why would the tutorial be written in such a way that it won't work even if you follow it?


I'm sorry I ranted earlier (again) I feel "old", like everything is moving too fast and I can't catch up.

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord

The Merkinman posted:

I'm sorry I ranted earlier (again) I feel "old", like everything is moving too fast and I can't catch up.
Welcome to the current world of javascript

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

It does kind of suck, but I also feel like it's not all churn for the sake of churn...technologies are getting better.

I've not done much frontend work in a few months...I just know I'm going to have to spend a day catching back up with whats going on on my next front end project.

Tivac
Feb 18, 2003

No matter how things may seem to change, never forget who you are

Kekekela posted:

Goons please share your experiences with Jest. I'm thinking of putting some time into it.

I've tried it several times...

https://twitter.com/tivac/status/798402354596970497
https://twitter.com/tivac/status/800796474334285827
https://twitter.com/tivac/status/811108589448237056

It's ok, now that they've got easier single-process mode I keep meaning to loop back around on it. Never got around to trying out the snapshot stuff.

Tivac fucked around with this message at 23:55 on Feb 3, 2017

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



The Merkinman posted:

I dunno, am I? I only say it that way because I'm just following the linked tutorial
I see ` in app.js
code:
const root = document.querySelector('#root')
root.innerHTML = `<p>Hello webpack.</p>`
But the tutorial said to add babel-loader with an es2015 option. Shouldn't that compile it so it works, or am I misunderstanding what that does?

If the back-tick is what it is complaining about, why did webpack --watch work but npm run build not work?
Also, more rhetorical: Why would the tutorial be written in such a way that it won't work even if you follow it?


I'm sorry I ranted earlier (again) I feel "old", like everything is moving too fast and I can't catch up.

Use semi-colons you madman

edit: my theory is that webpack might have uglifyjs built in to compress the bundles .js file, and uglifyjs might just support ES5 instead of ES6, so unless you have BabelJS or something similar compiling your code to ES5, UglifyJS has no idea what a backtick is or what to do with it.

If that's correct then `webpack --watch` probably builds a development version of the file that isn't minified through uglifyjs, so there's no parsing error since uglifyjs never touches it, `npm run build` just calls `webpack -p` (I took a look at that tutorial's example repo, in package.json at the root) which seems to be a production build that will call uglifyjs and blow up.

If that's correct then you either don't have babel, you don't have it set up right, or you don't have it configured in webpack right so it doesn't compile it to ES5.

edit: if all of this is true then that'll be pretty funny, since most browsers support 99~% of ES6 features at this point, so you wouldn't even need BabelJS if it weren't for UglifyJS

piratepilates fucked around with this message at 00:58 on Feb 4, 2017

Kekekela
Oct 28, 2004

The Merkinman posted:

I dunno, am I? I only say it that way because I'm just following the linked tutorial
I see ` in app.js
code:
const root = document.querySelector('#root')
root.innerHTML = `<p>Hello webpack.</p>`
But the tutorial said to add babel-loader with an es2015 option. Shouldn't that compile it so it works, or am I misunderstanding what that does?

If the back-tick is what it is complaining about, why did webpack --watch work but npm run build not work?
Also, more rhetorical: Why would the tutorial be written in such a way that it won't work even if you follow it?


I'm sorry I ranted earlier (again) I feel "old", like everything is moving too fast and I can't catch up.
It might be worth replacing the ` with a ' in the snippet to verify that fixes it.

I've seen some odd behaviors and github issue slapfights over -p and now just do something like for my build:
code:
NODE_ENV=production webpack --optimize-minimize --progress
Does your linter complain about anything in the code?


edit: Also, and maybe I'm just tired here, but it seems weird that uglify is working on bundle.js, as when its part of the build chain for me its showing errors in the source files not the bundle.js. I guess it could just use source maps for that though.

Kekekela fucked around with this message at 01:37 on Feb 4, 2017

ModeSix
Mar 14, 2009

The Merkinman posted:

I dunno, am I? I only say it that way because I'm just following the linked tutorial
I see ` in app.js
code:
const root = document.querySelector('#root')
root.innerHTML = `<p>Hello webpack.</p>`

As dumb as it is, use ' instead of ` it appears your fancy single open quote is causing the compiler to poo poo itself.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
I started a React app, and I want to use a custom Javscript file with just plain Javascript and use a script tag in the index.html file.

This is very difficult for me in React. I keep getting a syntax error as an unexpected "<" I haven't even written any React code yet, but I can't even get this to work? How do you write a JS file in React?

ddiddles
Oct 21, 2008

Roses are red, violets are blue, I'm a schizophrenic and so am I

Grump posted:

I started a React app, and I want to use a custom Javscript file with just plain Javascript and use a script tag in the index.html file.

This is very difficult for me in React. I keep getting a syntax error as an unexpected "<" I haven't even written any React code yet, but I can't even get this to work? How do you write a JS file in React?

What build tool are you using?

HaB
Jan 5, 2001

What are the odds?

Grump posted:

I started a React app, and I want to use a custom Javscript file with just plain Javascript and use a script tag in the index.html file.

This is very difficult for me in React. I keep getting a syntax error as an unexpected "<" I haven't even written any React code yet, but I can't even get this to work? How do you write a JS file in React?

Is there some specific reason you want to do that?

React is pretty opinionated about where it wants code.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Grump posted:

I started a React app, and I want to use a custom Javscript file with just plain Javascript and use a script tag in the index.html file.

This is very difficult for me in React. I keep getting a syntax error as an unexpected "<" I haven't even written any React code yet, but I can't even get this to work? How do you write a JS file in React?

You just put the script tag in your html. It doesn't have anything to do with React.

That being said, you probably shouldn't do this and include your js via an import so webpack or whatever can bundle it for you.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Grump posted:

I started a React app, and I want to use a custom Javscript file with just plain Javascript and use a script tag in the index.html file.

This is very difficult for me in React. I keep getting a syntax error as an unexpected "<" I haven't even written any React code yet, but I can't even get this to work? How do you write a JS file in React?

I also answered you in the other thread you asked this in.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
yeah I figured it out. I was originally importing the script into the component, as it should be, but I had onClick functions that were supposed to be hiding/showing a form, and that part should have been built into the component, rather than outside of it.

I'm dumb. The thing has been working all day, and I didn't even realize it.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
I'm finally getting an opportunity to establish a "styleguide" for a project I'm working on. It's making me appreciate SCSS all the more, including breaking things up into different partials, calculating dimensions (not talking about calc(), but the #{} convention) based on constants, not to mention @mixins. Oh @mixins, how do I love thee? Let me count the ways... ;-*

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Grump posted:

yeah I figured it out. I was originally importing the script into the component, as it should be, but I had onClick functions that were supposed to be hiding/showing a form, and that part should have been built into the component, rather than outside of it.

I'm dumb. The thing has been working all day, and I didn't even realize it.

Not sure if your example up there is what you are talking about, but mixing jQuery and React without a firm understanding of how React handles DOM is a recipe for headaches. If the two don't interact in any way on your page, go nuts though.

luchadornado
Oct 7, 2004

A boombox is not a toy!

Lumpy posted:

Not sure if your example up there is what you are talking about, but mixing jQuery and React without a firm understanding of how React handles DOM is a recipe for headaches. If the two don't interact in any way on your page, go nuts though.

Sounds like you've never experienced the bliss of working in a giant SPA that is jQuery BBQ wrapped by Angular, with a dash of React thrown in (using both Flux and Redux of course).

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Helicity posted:

Sounds like you've never experienced the bliss of working in a giant SPA that is jQuery BBQ wrapped by Angular, with a dash of React thrown in (using both Flux and Redux of course).

I think you have to commit a small genocide to reach that level of Hell.

TheCog
Jul 30, 2012

I AM ZEPA AND I CLAIM THESE LANDS BY RIGHT OF CONQUEST

Helicity posted:

Sounds like you've never experienced the bliss of working in a giant SPA that is jQuery BBQ wrapped by Angular, with a dash of React thrown in (using both Flux and Redux of course).

Doesn't Angular use jQuery light, or if jQuery is present sort of absorb its powers?

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

TheCog posted:

Doesn't Angular use jQuery light, or if jQuery is present sort of absorb its powers?

It does not USE it, so much as it has a built in jqLite library. If jQuery is already loaded, jqLite will not be.

However, the main point is that the major feature modern SPA frameworks provide is managing the DOM for you, so you should be trying to let the framework do that, and not jumping in and out with jQuery and other manual DOM manipulation unless absolutely necessary.

Skandranon fucked around with this message at 19:48 on Feb 5, 2017

luchadornado
Oct 7, 2004

A boombox is not a toy!

I guess the DOM manipulation part of it isn't even the horrible part - it's the lack of orthogonality. Unit testing BBQ state that drives jQuery widgets is nearly impossible, and we've got 50-75 widgets consisting of 300-1000 lines of code each. It took 8 dev days just to cleanly remove the dead BBQ code because it was so tangled up with other, important things.

As much as I get annoyed with Abramov's lackadaisical approach to Redux at times, I am really glad that he and others are recognizing and promoting the value of concepts that have been around forever, but have typically been absent from the JavaScript world. Event sourcing is a key example.

Pollyanna
Mar 5, 2005

Milk's on them.


Another React-Redux question. Is there a reason you have to make a component handle its own state and when to update vs. just passing down props and dispatching parameterized actions for when global state needs to be updated? Forms in particular are kind of confusing to me, and that's where the majority of our weirdass code lives since our app is basically an overgrown form with some API calls.

My fellow dev and I are getting really frustrated with the wonky, un-Redux-like code that our forms use because all the tutorials and documentation we read use and advocate for approaches wildly different from what we have in our codebase, so we don't feel like we're learning properly enough to contribute. It's getting a bit dire.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

Lumpy posted:

Not sure if your example up there is what you are talking about, but mixing jQuery and React without a firm understanding of how React handles DOM is a recipe for headaches. If the two don't interact in any way on your page, go nuts though.

Yeah I'm only using a bit of Jquery to handle a form submission and pushing the input of a form to an array. And then I'm importing that script to the form component.

My only issue I've been having is that I'm hiding/showing form based on state and I'm having problems getting the script to run correctly after the button to render the form is clicked. I understand that the script isn't running because it can't find #addform on the page because <Form/> hasn't been rendered yet, but I don't get why it won't work after <Form/> has been rendered.

My logic:

code:
import $ from 'jquery';

//will hold an array of people objects
var list = [];

//constructor that builds new people to add to address book
function Person(first, last, email, address, phone) { //new person constructor
    this.firstName = first;
    this.lastName = last;
    this.email = email;
    this.address = address;
    this.phone = phone;
};

$(document).ready(function () {
    // When the submit button is clicked, create a new person and add the values of
    // the form fields  to the properties of the object
    $("#addform")
        .submit(function (e) {
            e.preventDefault();
            var person = new Person($("input[name = 'fname']").val(), 
							$("input[name = 'lname']").val(), 
							$("input[name = 'email']").val(), 
							$("input[name = 'address']").val(), 
							$("input[name = 'phone']").val());
            list.push(person);
            console.log(list);
        });
});
The form component

code:
import React, {Component} from 'react';
import './custom.js';
import FaClose from 'react-icons/lib/fa/close';

class Form extends Component {
    render() {
        return (
            <form id="addform">
                <input type="text" name="fname" placeholder="First name" required />
                <input type="text" name="lname" placeholder="Last name" required />
                <input type="email" name="email" placeholder="email" required />
                <input type="input" name="address" placeholder="address" required />
                <input type="tel" name="phone" placeholder="phone number" required />
                <input type="submit" id="submitbtn" value="Submit"/>
                <button type="button" id="closebtn" onClick={this.props.onClick}><FaClose/> Close</button>
            </form>
        );
    }
}

export default Form;
App.js, where am rendering <Form/>

code:
import React, {Component} from 'react';
import './App.css';
import AddBtn from './AddBtn.js';
import Form from './Form.js';

class App extends Component {
  constructor(props, context) {
    super(props, context);

    this.state = {
      formVisible: false
    };
  };
  showForm = () => {
    this.setState({formVisible: true});
  }
  hideForm = () => {
    this.setState({formVisible: false});
  }
  render() {
    return (
      <div className="header">
        <h1 id="p2">Contact Book</h1>
        <form className="search">
          <input type="text" name="search" placeholder="Search by last name"/>
          <button type="button">Search</button>
        </form>
        {this.state.formVisible // NOTE: Script doesn't work because Form is not rendered by default!!
          ? <Form onClick={this.hideForm}/>
          : <AddBtn onClick={this.showForm}/>
}
      </div>
    );
  }
}

export default App;

spacebard
Jan 1, 2007

Football~
Maybe do your form logic in an onSubmit attribute on the form element instead? It would couple your components to state, but probably that's what needs to be done in this case.

This is were redux might help for managing state or in other words the list of Persons. :v:

luchadornado
Oct 7, 2004

A boombox is not a toy!

Pollyanna posted:

Another React-Redux question. Is there a reason you have to make a component handle its own state and when to update vs. just passing down props and dispatching parameterized actions for when global state needs to be updated? Forms in particular are kind of confusing to me, and that's where the majority of our weirdass code lives since our app is basically an overgrown form with some API calls.

React and forms are not simple yet. I'm not sure I understand the question - Redux encourages a single global state, but you can have local state in your components. There is nothing forcing either approach or preventing a mix of the two. Although I don't like the overhead of local state in components, I tend to prefer the encapsulation it provides when doing forms. My global state doesn't need to track when someone types something into a field.

Grump posted:

Yeah I'm only using a bit of Jquery to handle a form submission and pushing the input of a form to an array. And then I'm importing that script to the form component.

For starters, there's no reason to use jQuery for what you're doing. Besides not being terribly useful (http://youmightnotneedjquery.com/) it looks like you're trying to mix event binding and DOM manipulation with jQuery and how React works. That's going to be incredibly painful. Just fully embrace React.

You've got that jQuery file and that Form component coupled in a weird way. Move the binding of the submit event into your Form component so it gets bound then the component is rendered. Right now, document ready is firing, you're binding to a jQuery selector that evaluates to nothing, and then when you actually mount your component of course nothing will be bound to it.

Ultimately, you'll need a better way to manage your state. You can roll your own, but it's not fun. Flux is over-complicated. Redux is currently the go-to way for managing state in React. I'd highly recommend using React and Redux together. Before you hop into Redux, look around for a few 10-15 minute explanations of Event Sourcing. Once you generally understand event sourcing, you'll understand why Elm was written the way it was, and why Redux copied Elm. Don't fight the architecture or you'll be in pain.

If you want to think of it in a Redux way, I'd create a function to get values out of the form and create a new Person, and bind an action creator to the submit event that dispatches an action called 'addUser'. Your list shouldn't be a var just hanging out in the scope of that one module with jQuery stuff, your Redux store should have a 'users' property that you expose via selector aptly named 'getUsers'.

Once you're at that point, you can start struggling with validation and whether to track form state globally or locally. I'd probably suggest global state for beginners as the performance hit shouldn't be noticeable, and it's way easier to manage.

luchadornado fucked around with this message at 04:15 on Feb 6, 2017

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

Another React-Redux question. Is there a reason you have to make a component handle its own state and when to update vs. just passing down props and dispatching parameterized actions for when global state needs to be updated? Forms in particular are kind of confusing to me, and that's where the majority of our weirdass code lives since our app is basically an overgrown form with some API calls.

My fellow dev and I are getting really frustrated with the wonky, un-Redux-like code that our forms use because all the tutorials and documentation we read use and advocate for approaches wildly different from what we have in our codebase, so we don't feel like we're learning properly enough to contribute. It's getting a bit dire.

In a Redux based app, React components should rarely hold their own state, and if they do, it should almost always related to some visual property that only that component or its children care about.

There are a few forms libraries out there, I've used redux-forms with success, but I haven't used any others to know if it's the go-to solution these days.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply