Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
acemarke
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
94 ms
·
811.
▲
by
acemarke
7y ago
React batches updates that were queued from within its own event handlers. So, if you had: setA(1) setB(2) setC(3) in a single click handler, there would be a single render, and a single call to the `useMemo()` callback. O
812.
▲
by
acemarke
7y ago
For whatever reason, I've never understood the point or actual benefit of virtualenvs. Having lived more in the JS ecosystem for the last several years, my ideal workflow would be a copy of how the Yarn package manager works: - Top-lev
813.
▲
by
acemarke
7y ago
That's literally my point. Folks learning React will do that at first, because they don't know better. We _have_ caught that in code reviews, taught them not to do that, and moved on. But yes, it is an actual thing I have seen pe
814.
▲
by
acemarke
7y ago
I can describe both of those pretty simply (I think). React uses simple objects called "fibers" to track metadata for every component in the tree. When you begin rendering a function component, React creates a linked list of hooks
815.
▲
by
acemarke
7y ago
And to code-golf it a bit further, it can just be: useEffect(f, [])
816.
▲
by
acemarke
7y ago
Negation just includes the opposite boolean value in the array. _If_ that value at that index happens to be different than the last time the component rendered, the effect will run again.
817.
▲
by
acemarke
7y ago
Hooks definitely bring a different set of tradeoffs, especially compared to Higher Order Components. I'm a Redux maintainer, and the React-Redux API is a good example of this. The `useSelector` and `useDispatch` hooks are way easier
818.
▲
by
acemarke
7y ago
Would it be _possible_ to implement hooks as part of classes? Sure, it's just software, code can implement basically anything. But, the React team deliberately opted to only implement hooks for function components for a few reasons: -
819.
▲
by
acemarke
7y ago
I've seen a _lot_ of folks put multiple separate `setState` calls in a row, one for each field they want to update. I make sure to point out that it's nicer to read if they're collapsed into a single call, but it's a ve
820.
▲
by
acemarke
7y ago
We also recommend using Immer with Redux [0], and it's used internally in our new Redux Toolkit package [1]. [0] https://redux.js.org/style-guide/style-guide#use-immer-for-w... [1] https://redux-toolkit
821.
▲
by
acemarke
7y ago
Not sure what you mean by "boilerplate for thunks". You write thunks the same way you always have. And yes, `createSlice` explicitly supports responding to actions that were defined elsewhere in the app, using the `extraReducers`
822.
▲
by
acemarke
7y ago
Per the last comment, please check out our new official Redux Toolkit package. It includes utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire &quo
823.
▲
by
acemarke
7y ago
What "course" are you referring to? The link goes to an open-source "Real World" app example project. It's a community thing, not owned by any one person or group as far as I know.
824.
▲
by
acemarke
7y ago
You might be interested in Rick Cook's "Wizardry" fantasy series from around 1990. A Silicon Valley programmer gets pulled into a fantasy world, and ends up writing a compiler for his own Forth variation that treats spells as
825.
▲
by
acemarke
7y ago
I honestly have no idea where NPM pulls its audit numbers from. If I open up npmjs.com right now, it says there's 1,153,926 packages in total on NPM. While CRA does have a bunch of transitive dependencies, I can guarantee that CRA do
826.
▲
by
acemarke
7y ago
Really? I hadn't looked at Webpack 5 yet. If that's the case, that's great!
827.
▲
by
acemarke
7y ago
Yeah, we changed the name from "Redux Starter Kit" to "Redux Toolkit" because folks were misinterpreting the word "Starter" to mean that it was a CLI tool like CRA, or that it was only good for beginners. Didn
828.
▲
by
acemarke
7y ago
Right, I was just trying to clarify that even as a non-newbie, CRA has benefits and is my tool of choice.
829.
▲
by
acemarke
7y ago
Nitpicking: last time I checked, it was around 1500. Which is still way too many, and I'd love it if the JS community would spend some time working on collapsing the dependency trees for widely used tools like Webpack.
830.
▲
by
acemarke
7y ago
Exactly. It used to be that every single React tutorial started with "First, we're going to install Webpack and Babel", and half the tutorial would be filled with configuring those before it even got to the React code. As a s
831.
▲
by
acemarke
7y ago
CRA's default template gives you several files in `/src`. In the default template, most of those files are intended as examples: - `index.js` is required as the entry point for the app - `App.js` is the main app component - `App.
832.
▲
by
acemarke
7y ago
I'm a JS and React _expert_, and I still use CRA all the time whenever I want to spin up a new project because I don't want to take the time to mess with all the build setup. I just want something that works right.
833.
▲
by
acemarke
7y ago
Yes, that's what happens if you eject. But the point is that ejecting is an absolute last-ditch option that almost no one should have to resort to. Most folks won't need to customize the standard CRA behavior. If you do, there&#x
834.
▲
by
acemarke
7y ago
No, because CRA explicitly encapsulates and hides all that functionality inside the `react-scripts` package. You only add a single dependency to your own app's `package.json`. All the config files are in `node_modules/react-scri
835.
▲
by
acemarke
7y ago
It's not removed, it's just being deprecated. I would assume it would only be removed in 4.0: > For TypeScript users, we're deprecating --typescript in favour of --template typescript.
836.
▲
by
acemarke
7y ago
No, they've both always been 100% open source (ignoring the complaints about React's previous BSD+PATENTS license). React is built by Facebook, while Vue is primarily built by Evan You (+ a team of core contributors). The "c
837.
▲
Learning and Using TypeScript as an App Developer and Library Maintainer
(blog.isquaredsoftware.com)
1 points
by
acemarke
7y ago
|
0 comments
838.
▲
by
acemarke
7y ago
The hooks API literally "hooks" into React's lifecycle, by allowing the ability to save state and force re-renders as needed. In addition, React-Table explicitly implements support for doing rendering of whatever React "
839.
▲
by
acemarke
7y ago
I did see someone suggest that maybe R-T v7 should ship with a component that implements the v6 API on top of the v7 implementation, but that would add a noticeable amount of overhead to the API and I'm not sure how much benefit there
840.
▲
by
acemarke
7y ago
And on that note, Tanner has put together a bunch of example CodeSandboxes for the various features [0] . For our own app, I basically copied most of the default rendering logic from those, applied styles to match the rest of our app, and
More ›