15 years experience in React
I've never worked for Facebook, and React was released publicly in 2013, so obviously, my title is not 100% true. I have not been using React for 15 years. #clickbait
What I have been doing though is writing UIs basically the same way in a very repeatable process and with simple principles for 15 years. Same rules same process and I've used it for all kinds of web libraries and before I got my hands on Prototype and script.aculo.us even vanilla JS when we called it DHTML. Works with UIKit with Swift and Objective-C when building for iPhone and iPad too. The code I write to build a UI while it looks very different today goes through the same steps my code did 15 years ago when I got my first job as a web developer.
Screenshot of the website for script.aculo.us
1. Don't be dogmatic
There's no need to be extreme about picking the absolute best way to do something. There's no perfect way to structure your folders and files. You can't pick the framework that will meet all your needs. What you can do is be pragmatic, make progress, and iterate.
If you need to get a demo of one screen ready to show the team then your choice of which library to use for network requests means nothing. Build the whole thing in a single file with whatever tools you have and know.
Learnt about why class components are dead in React and it's all about hooks now? Don't suddenly start converting files in the codebase 40 people commit to. Anything you learn other's need to learn too.
Really this applies to more than UI programming but it's my most important rule.
2. Look at your design and focus on layout and behaviour
Whether it's a sketch on a back of a napkin or a fully detailed high fidelity design there's two big things you should be focusing on first: layout and behaviour.
Because the vast majority of building a UI for a screen is drawing boxes and laying them out relative to each other. That is where so much of your impact is. You should always put effort into getting the colours, typography, and accents like borders and shadows correct but they come after.
Make sure to find all the margin's (space between boxes) and padding (space between a box edge and content). Talk and sketch out breakpoints which normally aren't as simple as xl, l, m, s, xs or desktop, laptop, tablet, mobile. Discuss content order by finding out what is most important. Finally reaching over into the next topic of behaviour make sure to ask what are navigation elements or landmark elements.
After this session you should know:
- What boxes are on the screen and the content in them
- The margin and padding between the boxes
- Any relative relationships between boxes (x pushes y out)
- Breakpoints in the design where things don't work with sketches that show what to do
- Content order, navigation elements, and landmark elements
Either in the same session or another one (I recommend one session) you should then discuss behaviour. This isn't as simple as when I click X it will make Y zoom around but should include many of the events that occur through the lifecycle of a UI.
- Click and touch events both for elements and the screen (tap, click, pinch, scroll, etc.)
- Keyboard events
- Screen lifecycle events (enter/exit, load/unload)
- ARIA considerations if you're building a custom component (do not add ARIA attributes to everything)
- UI element lifecycle events (enter/exit screen or viewport, load/unload, etc.)
- Device events (rotation, low power, dark mode, low motion)
3. Outside in - big brush strokes first
When you watch a lot of painters you'll see them lay down these big broad colours in large strokes to layout their painting then they refine and refine until they've got their new artwork. It can be really exciting and tempting to dive right into those tiny details that might mean a new challenge but it can be just as big a win to get 4 boxes on-screen laid out correctly.
If you've got a completely new app you'll be starting at the absolute top-level layout, new screen you'll start at the body of the screen and down, and if you've got a new section on a screen you'll be making space for that box and then filling it up. You should always start at the highest level of the layout you can and make your way down to the smaller details iteratively as you work down the layers and eventually into the most specific styling.
4. Fake it till you make it
Don't connect real data right away. In some cases, this might be a rule to break if you're working with stable data that is already easy to access. In most cases, I've experienced it's best to just add in some hard-coded or mock data to start with, especially if you use tools like Storybooks where you can create example variations of the UI in different data conditions.
I find this also helps disconnect the UI from the way the data is actually sent, retrieved, and computed allowing for those parts to be better tested independently with unit tests and integration tests while the UI can then be tested using some kind of snapshot testing. You can then build your UI with a clear interface of how to send data in, respond to events, and handle event data.
That's all folks
If you enjoyed these ideas and wanted to talk more I offer career coaching, mentoring, and training for programmers, web or mobile, front or backend. Reach out to me on LinkedIn
Well written and very good advice!