15 ms·
Lessons learned as a React contractor
- kuon 10y agoAbout the "go without redux point", I've switched to MobX, and it helped me greatly for this, as I can implement proper state handling very quickly even when the project is in it's infancy. You just create a class, throw @observable in it and boom, you get everything without any boiler code.
- purplerabbit 10y agoI second this. In my experience Mobx actually speeds up initial development. And it is easy to learn. The same cannot be said for Redux.
- thomasrognon 10y agoI used redux for a year before switching to mobx (which I've now used for more than a year). It is easier, faster, simpler, and scales better in my experience. I can't recommend it enough.
- sandGorgon 10y agowhy did you do this ? we are already on redux.. but have been looking at redux with some interest.
- auvrw 10y agomobx looks neat ... have been using alt.js as a (similar, i think?) middle of the road solution between _all_ of redux's patterns and no flux at all.. .. i'm also told that, if all you're doing is rendering templates, you might not need anything more than hyperx (a substack production).
- mamp 10y agoMobX is great to get going quickly and it has good performance. However, in my experience, with a team Redux is great because it enforces a standard approach and clear representations. Well worth the boilerplate overhead.
- iamcasen 10y agoI'm surprised there is no love for nuclear-js in this thread. I personally didn't like redux's approach, but I understand where it's coming from. Nuclear-js feels heavy-handed, and there is indeed a lot of boiler plate, but in the end the explicit organization pays off in a huge way. What most people don't realize is that state management will get insane past a certain point. Nuclear-JS can handle a truly massive application that is very complex -- think google docs/sheets I imagine most people aren't building something like that though, and find it too cumbersome.
- unsoundInput 10y agoI am very confused what kind of state management MobX implements, especially after reading their current README (https://github.com/mobxjs/mobx/tree/6ed404b96a8b4074a473accd2bc22eda7223d924 https://github.com/mobxjs/mobx/tree/6ed404b96a8b4074a473accd...) Is it Ember/Vue-style "mutate, observe, compute" as implied by most of their example code or Flux-style as implied by their introduction visualization (https://github.com/mobxjs/mobx/raw/6ed404b96a8b4074a473accd2bc22eda7223d924/docs/flow.png https://github.com/mobxjs/mobx/raw/6ed404b96a8b4074a473accd2...)? Do I create actions or just mutate state directly (again, visualization and some text in the readme vs examples)? How is "observer turns React (function) components into derivations of the data they render." any different from just plain React components? MobX feels like someone tried to make an easy state management solution (obviously a great goal) and in the process just threw together whatever pattern exist out there right now. It obviously works for many people, considering how often someone comments about it on HN, but I wonder what makes those user stick with React vs a framework that completely embraces this approach like Vue or Ember. Is it some hard requirement on React?(EDIT: Or maybe preference of JSX?)
- hoodoof 10y agoMy lessons that I would add to this: lessons 1: there's a good chance, depending on what you are doing, that you do not need Redux - avoid it if you can. much docunentation seems to imply that it is a necessary hand in hand element of react development - not true. I have never found any situation in which I need redux. lesson 2:' use "create-react-app", and if humanly possible, don't eject from it.
- krrishd 10y agojust curious, why is ejecting from create-react-app bad? some of the symlinking stuff involved with create-react-app feels unnecessary but I still value the amount of boilerplate it takes out
- acemarke 10y agoMostly because you can get the benefit of improvements to the build config just by updating the one `react-scripts` dependency. For example, 0.8 enabled proper sourcemaps support in Webpack (and 0.8.2 bumped the Webpack dependency to fix a problem with not being able to set breakpoints in sourcemapped code). If you eject, you don't get those easy updates, as the config files are now a permanent part of your own project.
- jowiar 10y agoThere are a couple dealbreakers for now, but I'm seriously looking forward to the day I can migrate our stack ON to create-react-app largely for this reason. Having other people working to make my dev experience better is a huge plus.
- chrisweekly 10y agoNext.js (built on top of React and Redux, by the ppl who brought us socket.io) is a zero-config option that looks way better to me than CRA.
- hoodoof 10y ago
- ferdbold 10y ago"Linting also helps catch errors like reassigning consts and speeling errors" Hehe.
- binocarlos 10y agosagas are a steep learning curve and absolutely knowing what a generator function is essential before opening the docs. They are a very productive tool and worth the time imho. They allow your redux containers to concentrate on selecting state and triggering actions and the async stuff stays out of the way in 'workers'. Defo worth a look if your redux project has more than a few pages.
- adregan 10y agoI'm using redux-observables (very similar conceptually to sagas but uses rxjs) and allowing redux actions to remain pure and synchronous has made testing a breeze. Middleware has quickly become the most important redux feature for me.
- cnp 10y agoRedux saga is so elegant it makes me want to cry - but you have to understand generators first, as the author states. Once you get that part, then there's really no going back. Much simpler (and far lighter) than redux-observable.
- sergiotapia 10y agoI shudder at the complixity of Redux. Ooh~ nice, you dispatch an action to a reducer, ooh~. ~job security~ I don't know, it rubs me the wrong way when there are better tools out there. Mobx, is much quicker to integrate and is easier to understand how to integrate anywhere in a React app. Glad to see I'm not the only one who really doesn't like Redux. I mean check it out, it has an incredibly small API, and even smaller if you use the right Webpack loaders. import { observable, observe, toJS } from 'mobx' export default class Store { @observable foo = [] } Then in your components just set or read from `this.context.store.foo`. Every component using the same store will update it's reference to foo. https://sergiotapia.me/using-mobx-and-react-to-build-an-instant-search-3eae1dd20cbd#.2d0j5dbqa https://sergiotapia.me/using-mobx-and-react-to-build-an-inst...
- ergothus 10y agoAs someone that has recently started using Redux over Flux, how does Mobx handle nested dependencies? e.g. when you change selected item in store 1, it will impact items in store 2. (Redux doesn't have a great solution to this - it puts it all in the action handler - but it is consistent and means you components don't need to understand any of the store logic.)
- hugozap 10y agoYou can have a computed field in store 2 that computes the items based on the observable item in store 1, Whenever item 1 changes, the computed observable is updated automatically
- rlp 10y agoI agree, MobX felt much more natural to me when dealing with CRUD-style apps, there was very little boilerplate. Redux is great for apps with extremely complex workflows, but that's fairly rare in my experience.
- Waterluvian 10y agoRedux is like 200 lines of code and very explicit without any magic. What exactly is complex about it? I think too often people don't appreciate that redux, like all frameworks is a trade-off and is often the wrong tool for the job. Speaking about it as if it's a generic framework to trade out for another framework is a sign that it's being selected for the wrong reasons. If it's not making your life easier, you probably shouldn't be using it for that application. It's a really nice framing hammer, not a multitool ;) When I got into front end, I used redux for a small SPA with about a dozen actions and didn't really get it. "I could do this with react and basic JavaScript. Why am I writing so much extra?" I refactored redux out and it was much better. I have another application that interfaces with a number of APIs, is a very thick client and needs to recover from local storage on startup. Redux fit like a glove!
- mstijak 10y agoI would recommend Cx to all React contractors. Cx runs on top of React and solves many React/Redux pain points. It also offers comprehensive widget library and charts. http://cx.codaxy.com/ http://cx.codaxy.com/ Disclaimer: I'm the author.
- k__ 10y ago> I would recommend Cx to all React contractors. But your licence scheme seems to favour devs who only work for one company a contractor would get a new one for every project.
- mstijak 10y agoThat's true. It's your client who should provide the license. I guess if you're switching projects very often this is a problem, so feel free to contact us and we'll come up with a model that works for you.
- Silhouette 10y agoThis is a library that seems to do something a lot like what lots of other libraries do, except this one costs hundreds of dollars per developer, comes with only a year of support, and has many obvious problems with its licence such as being revocable, being ambiguous about jurisdiction, and literally having the word "DRAFT" stuck at the top of the first page.
- mstijak 10y agoThe licensing stuff is hard. I believe that our license is fair, even if it's complicated. You're right, many free projects offer the same or even greater functionality, however, you're not taking into consideration time you spend to put everything together. If your client is paying you hourly, Cx is an investment which pays off quickly. We're contractors too and this was one of the reasons behind Cx. I understand that commercial licenses are not very popular these days, but for a small company like ours, I don't see any other model allowing us to concentrate on support and the product in the long term.
- zem 10y agowhat i've found over the course of my career is that the most invaluable feature of boilerplate and scaffolding apps is to get a known-good build pipeline up and running. a trick i've often found useful when migrating to a new framework is to autogen a starter project and then start copying bits of my existing project into it and getting them working. when i'm done, i usually understand the new system well enough to go backport my changes to the existing project (if i want to preseve git history) or simply start afresh once all my tests are passing. it is a sad commentary on the state of software development that the build process is the most complicated and headache-inducing part of exploring a new language or framework, but i've found that to be a constant across many languages and many years.
- forgottenacc57 10y agoTry create-react-app
- deleted 10y ago[deleted]
- armandososa 10y agoOK. Here's what I've learn after ~2 years of doing react myself. 1. Wrap third party components, so you can swap them easily if they become unstable or you find something better. 2. If you have a codebase that predates create-react-app, take a look into its configuration, webpack is a complex beast and they've figured many optimizations. 3. Learn the concept of High Order Components and use them to abstract common functionality (for example, retrieving data from an API) 4. Even if you use Redux (I do and I love it), not everything belongs in there, use local state whenever it makes sense first. 5. Never, ever, depend on anything inside `react/lib`
- rtpg 10y agoThe more I've thought about this the more I think the first point is the best decision for every long-lived application. Wrap _all_ third party library calls. This lets you reduce the scope of these calls to "approved" ways and make much stronger assertions about who's doing what in your code. This gets super useful the further down the line you get to adding really complex features. Being able to isolate all the places where certain objects get created to add a permission check is nice. It also makes testing easier because you have some nice entry points to mock. Raw usage of things like an ORM can let you get through a prototype super quickly, but makes editing the application later on quite hard.
- mathw 10y agoYes. Definitely. I have benefited enormously from doing this in C# for a few years now. Certainly the wins in testability can be significant, but it also isolates the third-party dependency's behaviour and lets you wrap it with something that exposes the interface you actually wanted. Which you can test in isolation and be confident in. It's a shame it's really really tedious though!
- galephico 10y agoSincere question: do you really have the feeling the over cost is worth it? Do you do this for EVERY external library you're using?
- tzaman 10y ago> 4: Raw SVG >= D3 for simple data visualisations You can have a bit of both. D3 has a dependency "d3-scale" [0], which is a perfect choice if you'd like D3 to do the math and React to take care of the DOM. 0: https://medium.com/@mbostock/introducing-d3-scale-61980c51545f#.3ohtn0oj9 https://medium.com/@mbostock/introducing-d3-scale-61980c5154...
- swah 10y agoYesterday I wanted to find horizontally scrollable JS charts and had a hard time.. any tips?
- forgottenacc57 10y agoFor all the people who use redux - a question - how is redux better (for your use case) than just a global variable?
- acemarke 10y agoLots of reasons: - Isolation of "write logic" means you know where to look to see what code is updating a given chunk of state - Consistent state handling means it's a lot easier to think about what's going on in the application - The DevTools show you a log of dispatched actions, and enable you to step back and forth between states to see what the UI looked like at each point - Middleware lets you centralize app-wide logic, such as consistent transformations for AJAX responses - Redux's constraints (such as wanting state to be serializable) enable a number of other use cases, such as persisting state across page reloads and synchronizing multiple stores remotely. - There's a rapidly growing ecosystem of addons and utilities for specific use cases (see https://github.com/markerikson/redux-ecosystem-links https://github.com/markerikson/redux-ecosystem-links )
- forgottenacc57 10y agoI've built a pretty large react app and never needed these things. Things like stepping back through state seem honestly to me to be a gimmick not worth the required investment of time and pain.
- acemarke 10y agoI've seen a number of people make comments to that effect, and I genuinely don't understand that point of view. I use time-travel debugging on a daily basis, and it's a _huge_ time-saver for me. I also don't understand the "required investment of time and pain" comment. I've got a couple lines in my store configuration that sets up the Redux DevTools extension, and after that, It Just Works (TM). In fact, one of the posts in my "Practical Redux" tutorial series shows how to configure it: http://blog.isquaredsoftware.com/2016/11/practical-redux-part-3-project-planning-and-setup/ http://blog.isquaredsoftware.com/2016/11/practical-redux-par... .
- deleted 10y ago[deleted]
- thght 10y ago> Happy 2016?
- griffinmichl 10y agoDefinitely agree with #1. If there's one way I've changed as a programmer as I've gotten more experienced, it's that I DGAF about repeating myself.
- drum 10y agoOther things I'd add after building a React project: 1. "Configuration over Convention" seems to be the mantra with build settings and organization of the entire application. This can make adding features slower if you're used to frameworks like Rails. 2. SEO will require additional effort via server side rendering
- mikebay 10y agoI really wonder why so many it jobs are following these mainstream "licence hell" frameworks. Why facebook frameworks ? Why google platforms ? These spying giants are like Obama to world peace and we are close to WW3. Why people give they privacy so easy away? Does it even matter for people that NSA / CIA is spying you ? What actually anymore matters for people? Software development start to loose interest a bit in me. I hate to think that Facebook, Google and Apple create these internet ghettos where you cannot even create freely software, but people follow like dogs in lead. Developers, bosses please wake up.
- JTenerife 10y agoHere are my 2 cents: 1. Don't use a boilerplate. Not even create-react-app. Learn webpack and npm and TS / Babel. It's not that hard. 2. If you havn't yet, take a second look at MobX. I got it once I realized that I can organize my state just as I love it with Redux (normalized and update strictly through actions). With MobX you don't need Reselect. 3. Even though the React community seems to favor ES6, at least give Typescript a serious try.
- statictype 10y agoTypescript with react is awesome and I probably would find it difficult to go back to react without it. Getting type information in your editor when you are several levels deep in components is very useful. My only complaint is trying to figure out how to properly work with 3rd party react modules within typescript's own namespace system
- tomduncalf 10y ago> My only complaint is trying to figure out how to properly work with 3rd party react modules within typescript's own namespace system Could you be more specific about the issue you're having here? Might be able to help
- cheapsteak 10y ago>1. Don't use a boilerplate. Not even create-react-app. Learn webpack and npm and TS / Babel. It's not that hard. I can't say that I agree with this Hunkering down to learn build tools will probably yield the lowest ROI compared to nearly anything else you could be doing They're nice to know, sure, but you'll pick them up along the way as you use and modify them As you said, not that hard :) And +1 on MobX. Bee's knees
- geewee 10y agoHow did you get typescript working properly with redux? I never could figure out how to get proper types in my reducers or HMR to work.
- 10y ago
- wishinghand 10y agoNow I don't know what to believe: https://imgur.com/gallery/jL62c https://imgur.com/gallery/jL62c
- cdelsolar 10y agoDon't use it. I used something called JS stack from scratch (it's a github repo). You set it all up but along the way it teaches you everything. It worked perfectly. The only JS I'd done before that was Backbone stuff and requireJS.
- zappo2938 10y agoI about to convert backbone views in a standing app to React components. Then eventually convert the backbone app to React much later. Do you have any advice, tutorials, and code repositories that would help me?
- cdelsolar 10y agoThe "Thinking in React" doc on the main React page, and their tutorial, were greatly helpful, and it was about 80% of my reference docs. I didn't bother with trying to interface with existing Backbone models, but your app may be too huge to rewrite (it still took me several months to rewrite from scratch, but it's a side project so it probably would have been a few weeks if full time). That "js stack from scratch" repo is also very helpful in setting up the whole build.
- wishinghand 10y agoI'm more of a fan of Vue and it's CLI launcher, I was just pointing out the two high-visibility opposing views which I'm sure add to the frustration.js that devs old and new experience.
- lj3 10y agoI don't know if this sort of thing has me concerned or optimistic. On one hand, most ecosystems have a set of standard practices ("best practices"). This can take a lot of ambiguity out of learning and using a new ecosystem. On the other hand, some communities have chosen best practices that seem a little odd (I'm looking at you, PHP. If I wanted to write code in Java, I'd use Java). If nothing else, this makes asking React based interview questions complicated.
- linkmotif 10y agoAnd it's only been a year! <3. Wild ride.
- holografix 10y agoGiven the amount of React knowledge in the thread and the fact that I just finally groked Redux... what would you recommend to emulate something like ionic? MaterialUI + some sort of flexboxing?
- thomasrognon 10y agoFor a material design look, I've used material-ui, mdl, and react-md. react-md is the best in my opinion. Incredibly complete and polished for being done by essentially one person. https://github.com/mlaursen/react-md https://github.com/mlaursen/react-md
- Sophistifunk 10y agoDon't rely on lint to catch speeling errors. It doesn't work on imports. Flowtype or TSC (even without using any TypeScript syntax) are your friends.
- arbesfeld 10y agoI'm glad that the author mentioned sagas - this is one of the most underrated parts of using Redux and it makes a huge difference in async code. To be able to define complex asynchronous tasks as a series of "take", "call", and "put" has significantly reduced the number of bugs in our async code. Another point for Redux: it makes it much easier to understand bugs, both locally and remotely with a tool like our LogRocket (https://logrocket.com https://logrocket.com)
- jblok 10y agoLogRocket is truly fantastic.
- bayonetz 10y agoI find mockable end-to-end testing for React-based SPAs to be quite a mess. On the one hand, "React is a just a view library" so e2e testing is orthogonal. On the other hand, Redux/Flux + React pretty much get treated as the counterpart to traditional MVC and the infrastructure upon which you build your whole app on. But unlike Ember with it's QUnit e2e helpers or Protractor for Angular, there is nothing like that for e2e testing a "React [+ Redux/Flux]" app. Unit testing with TestItils/Enzyme/Jest definitely doesn't cut it. You can unit test all day but the isn't the same as integration and acceptance-type testing. We had to basically roll our own using WebDriver.IO and injecting a fetch-mock helper into our app to mock out the external API calls. That last part is key when you need to test your complex SPA without having to rely on backend API servers. Anbody else feel this pain?
- Zalastax 10y agoYou're completely right! It's unfortunate but the tooling for e2e tests isn't "there" yet. For now the best alternative is Selenium (which I've had a lot of trouble with getting stable) or https://github.com/DevExpress/testcafe https://github.com/DevExpress/testcafe
- dx034 10y ago> My tip: test on lower spec machines I wished ever developer would do that. Too many mobile apps or websites that do very simple stuff (displaying content, simple forms) don't work properly on older phones because of some sophisticated features that no one needs. Many developers seem to think that everyone uses the newest machines and flagship phones with high bandwidth, and forget about everyone else. Unfortunately the fear of premature optimization is so big for some people that their users have to suffer just because the programmer wanted to have a nicer developer experience..
- vinceguidry 10y agoThe real reason people don't do it is because it's really hard to make a part of your CI workflow. If the organization wants to dedicate resources to this, great, but this isn't something the dev team is really equipped to do all by themselves.
- etimberg 10y agoIt's definitely hard to do but tools like Selenium and Selendroid can make it easier (assuming you have someone who has the time and energy to set it up). Once you have system level tests running, then adding some phones or low-end machines is relatively straightforward.
- spraak 10y agoAre there any CI SaaS tools for this?
- huskyr 10y agoExcellent article! Lots of tips that are applicable to non-React projects as well (simple over customisable components for example).
- pmlnr 10y ago> January 2016, I changed my job title on LinkedIn to React developer So whenever I start working on a new area, I should add that to my job title? React Carpenter? http://www.jasonbock.net/jb/News/Item/7c334037d1a9437d9fa6506e2f35eaac http://www.jasonbock.net/jb/News/Item/7c334037d1a9437d9fa650... Also: > 1: Multiple simple components are better than one highly customisable one No shit. Ever heard of UNIX?
- swah 10y agoAnyone working on Windows? Is web pack still the way to go? How does it interact with something like phonegap?
- swah 10y agoAnyone working on Windows? Is web pack still the way to go? How does it interact with something like phonegap? I have 3 similar projects and I'm super confused which stack should I pick...
- krlkv 10y agowebpack is still the way to go. Windows or not.
- martijn_himself 10y agoTangential question: does anyone have experience moving from full time (.NET) development to freelance React / JavaScript development and is willing to offer advice? I'm currently employed as a senior .NET consultant and I am seriously considering changing stacks and trying contracting / remote work in order to have more freedom to travel and work from different geolocations amongst other things. Should I take some time off to learn React? Do I have to position myself as a junior React developer?
- bflesch 10y agoI think it is worth it. Once you get a grasp of React (and get a working webpack setup, which was difficult in the past) allows you to build apps for mobile (React native), desktop and web. We're hiring react developers in Hamburg, Germany :)
- martijn_himself 10y agoGreat, thanks for the heads up! :) Do you have any more information about your company, vacancies and hiring process? EDIT: a quick search has answered my question- no REMOTE positions I see :). Hamburg is a nice city though!
- vinceguidry 10y agoGenerally you'll find that a company is way more amenable to going full-remote after a few months of having you in the office at least three times a week. Just bring it up during phone screens whenever they ask "do you have any questions for us," after the obligatory company-focused question.
- bflesch 10y agoOh we're just a small startup with a node.js / react platform hosted on AWS. Due to our small size we have a simple and short hiring process, in which we try to hire smart, experienced people. As the sibling comment said we're also very open to remote working after a certain period of getting to know each other. I've refrained from adding the "REMOTE" keyword to our hiring posts because it attracts a lot of remote (non-)"talent", and we're being swamped in mails from people who don't fit the stated profile. We've been burned hard by remote-only employees in the past because it is very hard to keep the whole team on the same page, even more so with programmers inbetween junior and senior who want a lot of autonomy but end up delivering subpar results.
- HNSucksAss 10y ago"I started a contract to build a React component, only to discover the Backbone project it was to used in, was being compiled without dependency compilation. Implementing React components in Backbone is fairly straightforward, with Redux you can even communicate between the two. However, they can only communicate if they’ve been compiled together with Browserify or Webpack." Gibberish.
- chrislgrigg 10y agoThis is great advice, particularly the part about small, similar components instead of large, customizable ones. This is something I feel like I struggle with in views much more than I ever did working backend, and it's healthy to be reminded regularly. On the subject of sagas, does anyone have a good solution for dealing with `call` in TypeScript without losing type safety?
- blauditore 10y agoSome of these points are basically principles of (object-oriented) software composition, just applied to react. Some examples: - "Multiple simple components are better than one highly customisable one" -> Single responsibility principle [1] - "When all you have is two weeks, keep it lean" -> "Make It Work, Make It Right, Make It Fast." [2] - "embrace the toughest linting rules your team can stand." -> Not really a principle, but that's almost like simulating statically typed language with compile-time errors and warnings. [1]: https://en.wikipedia.org/wiki/Single_responsibility_principle https://en.wikipedia.org/wiki/Single_responsibility_principl... [2]: http://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast http://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast
- dahart 10y ago> My tip: embrace the toughest linting rules your team can stand. How good is the Flow type checker, vs ESLint or the Google closure compiler? While I don't disagree with anything the author said, most of the time I feel like ESLint is just a huge nag about white space. It's defaults have a bunch of rules that in my opinion enforce style without improving code safety at all, despite what the intro docs say. Someone I work with read some opinions like this one and got the idea that ESLint represents correct JS standards, and won't allow the white space rules to be relaxed. I'm stuck being forced to put a space after my comment characters, and not being able to line up blocks of repetitive code. It is admittedly nice to not have any white space style arguments. OTOH, I never really had white space arguments before, and the difference in both friendliness and code safety between using ESLint and the Google closure compiler is huge.
- caub 10y agoI think Redux, Flux and cie and totally useless if you know React well
- caub 10y agoI think Redux, Flux and cie and totally useless if you know React well