Redux Predictable State



100DaysOfCode – Days 13 & 14 – Redux

I have seen too many times Redux and React “holding hands” and it was time to know why was that. I finished the Redux module from freeCodeCamp and these are my notes to remember about it:

In Redux, there is a single state object that’s responsible for the entire state of your application. This means if you had a React app with ten components, and each component had its own local state, the entire state of your app would be defined by a single state object housed in the Redux store. This is the first important principle to understand when learning Redux: the Redux store is the single source of truth when it comes to application state.

  • This also means that any time any piece of your app wants to update state, it must do so through the Redux store. The unidirectional data flow makes it easier to track state management in your app.
  • An action creator is simply a JavaScript function that returns an action. In other words, action creators create objects that represent action events.
  • dispatch method is what you use to dispatch actions to the Redux store. Calling store.dispatch() and passing the value returned from an action creator sends an action back to the store.
  •  Reducers in Redux are responsible for the state modifications that take place in response to actions. A reducer takes state and action as arguments, and it always returns a new state. It is important to see that this is the only role of the reducer.
  • Another key principle in Redux is that state is read-only.
  • store.subscribe(). This allows you to subscribe listener functions to the store, which are called whenever an action is dispatched against the store. One simple use for this method is to subscribe a function to your store that simply logs a message every time an action is received and the store is updated.
  • A callback function is simply a function that get’s called after another function is done being executed.
  • In order to let us combine multiple reducers together, Redux provides the combineReducers() method. This method accepts an object as an argument in which you define properties which associate keys to specific reducer functions. The name you give to the keys will be used by Redux as the name for the associated piece of state.
  • To include Redux Thunk middleware, you pass it as an argument to Redux.applyMiddleware(). This statement is then provided as a second optional parameter to the createStore() function. Then, to create an asynchronous action, you return a function in the action creator that takes dispatch as an argument. Within this function, you can dispatch actions and perform asynchronous requests.

Now let’s make a mix and starting from tomorrow I’ll learn React with Redux.

React Hands on & Tips



100DaysOfCode – Days 8 to 12 – React

 I’ve spent the last few days learning more React, I needed to get to a point where I could solve simple tasks without copying the answer from other fellow, so I came back to freeCodeCamp and continue with the Front End Libraries Certification, just where I abandoned it because it was not getting the React concepts. Now after a week having my hands on in some code and easy problems, it has been quite a smooth path to follow and founding some interesting knowledge to keep in mind about React.

Here my list of things to have into account for my future React proyects:

  • The best practice with React is to place API calls or any calls to your server in the lifecycle method componentDidMount(). This method is called after a component is mounted to the DOM.
  •  The first is unidirectional data flow. State flows in one direction down the tree of your application’s components, from the stateful parent component to child components. The child components only receive the state data they need.
  • complex stateful apps can be broken down into just a few, or maybe a single, stateful component. The rest of your components simply receive state from the parent as props, and render a UI from that state. 
  • state updates may be asynchronous – this means React may batch multiple setState() calls into a single update. This means you can’t rely on the previous value of this.state or this.props.
  • Using a function with setState guarantees you are working with the most current values of state and props.
this.setState((state, props) => ({
  counter: state.counter + props.increment
  • One common way is to explicitly bind this in the constructor so this becomes bound to the class methods when the component is initialized.
  • stateless functional component is any function you write which accepts props and returns JSX.
  • stateless component, on the other hand, is a class that extends React.Component, but does not use internal state (covered in the next challenge).
  • stateful component is a class component that does maintain its own internal state. You may see stateful components referred to simply as components or React components.
  • The componentDidMount() method is also the best place to attach any event listeners you need to add for specific functionality. 
  • React provides a synthetic event system which wraps the native event system present in browsers. This means that the synthetic event system behaves exactly the same regardless of the user’s browser – even if the native events may behave differently between different browsers. (Cool!!!!)
  •  FYI: As a rule, any hyphenated style properties are written using camel case in JSX.
  • Since React is a JavaScript view library and you can run JavaScript on the server with Node, this is possible. In fact, React provides a renderToString() method you can use for this purpose.

JavaSwing JSplitPane



Today was a quick exercise with JavaSwing. It was to help someone who needed an easy GUI, but at the end it was of not use for the person, but for me was a way to check that I still can work with Java, the logic is applied the same way independently of the language, good to know!

#100DaysOfCode – Day 2 : JavaSwing

I had a small request about a GUI where two lists where displayed, left and right, the one in the left will show some values that when selected should fill the values of the list at the right side.

The user should be able to add new items to the lists and remove them.

I decide to have the view with a JSplitPane, the JList and DefaultListMode to add new items was the answer for the lists. Listeners where the key for the button functions.

The result:

A lot to be improved but for a quick exercise I think it was good enough.

React Fresh start



Hi there!

Today it’s my first day in the #100DaysOfCode, and I will start getting deeper with React. I already took some steps but I wanted for long to get a step forward, so here we go.

#100DaysOfCode – Day 1 : React

By now, I think we all know what React is and how well it’s rated right now, so I’m not going to waste your time, or mine, repeating what thousands of other sites can tell you. Without further ado, let’s get started!

How to get started with React – I found this “gem” in my “usual suspect” place to get all the good and free stuff about learning anything to do with coding, freecodecamp. It also includes a free guide to get React Ready with your JavaScript, is it not cool? I think it’s a great idea to know where you are and what you need to have to learn something. Well done, Chris!

Today, I read the JavaScript guide which I found clear and easy, I had a clear idea that I had all the knowledge needed and I continued with creating my new React app.

I had all the needed “weapons” to start the fight (Node.js, VSCode, etc) so I just had to type:

npx create-react-app my-app

And the magic started! I had a look in the contents and I will continue tomorrow with more React coding.

It was nice at least to get this stone rolling.