Been thinking a lot about component composition and how overlook this "feature" is in most codebases.
Reacr is ineheretrly composable one can argue that composition is the whole point of React and the component model.
So, why is not used more frequently?
One reason could be that: is not the default mental model.
Is like the default way we structure components in our minds is just inheritance. Containers containing more containers.
This approach of will definitely ends up in a prop drilling issue at some point.
But. What is prop drilling and why is an issue?
Prop drilling is a "feature" or at least capability of components to share data between them.
Props are the way components communicate each other. Is their API, and through this, you can pass data from a parent component.
Therefore prop drilling is the main technique to share data across components from parent to children. But why is considered an issue? Because at some point the component tree is so nested that passing props down is a pain since the data is required deep down in the tree.
This is when we should reach to composition. Most of this component usually are just "layout" thing instead of logic containers so they are just acting as proxies of the data passing it down to the next children. @mjackson have a very good tal about this.
So if is so nice why is not used more often? I think is just old behaviors that stick with us.
Proop drilling is often related with state management and was a big buzz word when Flux came into play and later Redux. (Old days).
Then we saw a solution tight there.
We started using Flux alike implementations moving everything outside of React tree trying to avoid prop drilling and hoping to replicate this model of Component as function of state. But we completely forgot of composition.
Later one Context became the norm and we still doing the same as before. Moving all of the shared data into one global store to share it across.
So, even tho Context is awesome IMHO is a very good tool for library authors but for app developers we should use composition more often and at same time do lote to make it a known concept.
If sounds interesting please RT the first tweet 👍👍
🎉 JOB ALERT @Clevertech is looking for experienced React Devs
Come work with an awesome and kind team (And with me 😅)
Fully remote positions with a really remote 1sr company.
If you're looking for level up your career this might be the opportunity.
Check the links below!
Do you know React and feel comfortable working with big codebases?
You enjoy working with JSX and composing hooks? clevertech.biz/careers/senior… start date June 1st!
You know React but also feels really comfortably with node and express?
Check this out!
He estado pensando mucho en la composición de componentes y cómo se pasa por alto esta "característica" en la mayoría de los proyectos.
React es inherentemente "componible", se puede argumentar que la composición es el punto central de React y el modelo de componentes.
Entonces, ¿por qué no se usa con más frecuencia?
Una razón podría ser que: no es el modelo mental predeterminado.
Es como si la forma predeterminada en que estructuramos componentes en nuestras mentes fuera solo herencia. Contenedores que contienen más contenedores.
Crear ese código definitivamente termina en un problema de prop drilling en algún momento.
State management in a web app can be a real PITA and confusing topic to tackle down.
The way that you handle the state is something you should take care of from the very beginning.
Starting for: what is state and what type of state do I have?
The application state can be split into at least two types :
🕙 Server state: asynchronous and doesn't really belongs to the app, remotely persisted, potentially out-of-date.
📺 UI state: synchronous, easily accessible, derived from user interaction. Complete ownership
Since the nature of the state is different in each case we should choose the correct tool and "architecture" to manage it.
There is a ton of solutions out there and I think that all of them are good one when used correctly.
Gracias a la lamentable pandemia la educación remota es pan de cada día tanto para nuestr@s niñ@s como también para adultos buscando mejorar sus conocimientos.
Hay muchos sitios y muchas formas de ofrecer y consumir contenido pero como hacer que sea educación efectiva?
Es un mundo complejo y claramente diferente para cada uno pero creo podemos dividirlo en grupos eta ríos buscando que funciona mejor para
- preescolares (tengo mis opiniones aquí)
- adolescentes
- universidad
- Adultos buscando mejorar su carrera
Me enfocare en el último punto
Ciertamente hay muchos servicios tanto de pago como gratis incluyendo YouTube
Pero creo q la única forma de hacer que el aprendizaje sea efectivo es más allá de simplemente consumir contenido.
Y aquí es donde la forma en que sea crea el contenido para incluir acción es importante
Just in case you are falling into a dark and deep TS rabbit hole with react-hooks-form.
If you want to have custom components that do something based on the `errors` that comes out of `useForm`.
That error object type is DeepMap<TFieldValue, FieldErrors>.
For some reason that I'm not in the mood to discuss xD I wanted to pass that errors down to a "generic" Input and friends component to show some error state.
But TS didn't like it. It said that I wasn't able to access `errors?.[props.name]` 😅
So I tried to bend the type system and I didn't actually fully accomplish that goal and the solution I had was really hacky and disgusting 🤮. And after digging in the code I had a bulb moment 💡
Is a design pattern that enable the user of a component to manipulate or manage the inner state of it by using a reducer pattern.
When creating components for an UI library for your project you have to take some decisions and assumptions about the way it work or be used.
But adding so many opinions to it can decrease the generalization of your component and the usability of the same.
The State Reducer Pattern (an idea an implementation by @kentcdodds for downshift) is a form of Inversion of Control where your component enable the user of it to control internal behavior through the API.