<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: A Dev</title>
    <description>The latest articles on DEV Community by A Dev (@jsdev25).</description>
    <link>https://dev.to/jsdev25</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F193649%2F48da54f5-2c4d-4190-98b6-be7dcc05c709.png</url>
      <title>DEV Community: A Dev</title>
      <link>https://dev.to/jsdev25</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jsdev25"/>
    <language>en</language>
    <item>
      <title>Simplest Redux</title>
      <dc:creator>A Dev</dc:creator>
      <pubDate>Fri, 11 Sep 2020 11:19:21 +0000</pubDate>
      <link>https://dev.to/jsdev25/simplest-redux-1o</link>
      <guid>https://dev.to/jsdev25/simplest-redux-1o</guid>
      <description>&lt;p&gt;This article is for someone who wants to implement redux without going into depth&lt;/p&gt;




&lt;p&gt;if you're in for only the code part skip to Implementation&lt;/p&gt;

&lt;h3&gt;
  
  
  Redux brief
&lt;/h3&gt;

&lt;p&gt;Redux is aimed to put the app's state at one accessible place for all components (single source of truth) called the store&lt;/p&gt;

&lt;p&gt;This store have our state, the store takes the reducers to adjust in the state depending on the actions taken by an interaction from the user adding item to cart or liking a picture&lt;/p&gt;

&lt;p&gt;Actions are objects who must have a type property&lt;/p&gt;

&lt;p&gt;Action creators are functions that return objects or functions&lt;/p&gt;

&lt;p&gt;reducers are clean functions who has no side effects&lt;/p&gt;

&lt;h3&gt;
  
  
  Middleware brief(Thunk - logger)
&lt;/h3&gt;

&lt;p&gt;middleware is made to intervene after an action is triggered and before it reaches the reducer aka making a change to the state&lt;/p&gt;

&lt;p&gt;thunk middleware is used for async actions and it gets triggered when the action creator returns a function not an object (redux-thunk npm)&lt;/p&gt;

&lt;p&gt;logger middleware is to log the action and the state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const logger = (store) =&amp;gt; (next) =&amp;gt; (action) =&amp;gt; {
  console.group(action.type)
  console.log('the action', action)
  const result = next(action)
  console.log('the new state' ,store.getState() )
  console.groupEnd()
  return result
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;Three dependencies needed, the first is "react-redux", the second is "redux" and the third is "redux-thunk" &lt;/p&gt;

&lt;h5&gt;
  
  
  index.js
&lt;/h5&gt;

&lt;p&gt;a- you take your Provider from react-redux and this will open the door to something called connect which in the end when applied will allow the consumer components consume state when passed through connect as props&lt;/p&gt;

&lt;p&gt;b- you create the store via createStore function from redux by passing to it as a first argument your reducer &lt;/p&gt;

&lt;p&gt;c- if multiple reducers you use combineReducers from redux&lt;/p&gt;

&lt;p&gt;d- CreateStore can take as a second argument the middleware through the applyMiddleware function which its arguments are the used middleware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {createStore, combineReducers, applyMiddleware} from 'redux';
import thunk from 'redux-thunk'
import {firstReducer} from './reducers/firstReducer';
import {secondReducer} from './reducers/secondReducer';
import App from './components/App';

// the logger function is a middleware function 
const logger = (store) =&amp;gt; (next) =&amp;gt; (action) =&amp;gt; {
  console.group(action.type)
  console.log('the action', action)
  const result = next(action)
  console.log('the new state' ,store.getState() )
  console.groupEnd()
  return result
}  

//creation of store
const store = createStore(
  combineReducers({firstReducer,secondReducer,moviesReducer}),
  applyMiddleware(thunk,logger)
)


ReactDOM.render(
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;Provider store={store}&amp;gt;
      &amp;lt;App /&amp;gt;
    &amp;lt;/Provider&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;,
  document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Reducer
&lt;/h5&gt;

&lt;p&gt;any reducer would be the same idea &lt;br&gt;
state is given its initial value which in this case is an object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const firstReducer = (state={},action) =&amp;gt; {
  switch (action.type) {
    case 'ACTION_TYPE':
      return {...state,value:action.payload}
    default:
      return state;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Actions
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//action taking an argument to set a value in the state 
export const actionCreator = (value) =&amp;gt; ({
  type:'ACTION_TYPE',
  payload:value
})


//another action that returns a function to be handled by
//thunk for async call to get for example movies
//you would create an action for loading and then another to
//set the movies
export const getMovies = () =&amp;gt; {
  return (dispatch) =&amp;gt; {
      dispatch(loadingMovies())
    return fetch('api')
    .then((res)=&amp;gt; res.json())
    .then((res)=&amp;gt;dispatch(setMovies(res)))
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Component A that creates the call
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import {connect} from 'react-redux';
import {getMovies} from '../../actions/movies'

class ComponentA extends React.Component{

  componentDidMount() {
    this.props.movies()
  }

  render(){
    return(
      &amp;lt;div&amp;gt;
       &amp;lt;p&amp;gt; i'm Component A let get those movies &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    )
  }
}

const mapDispatchToProps = (dispatch) =&amp;gt; ({
  movies: ()=&amp;gt; dispatch(getMovies())
})

export default  connect(null,mapDispatchToProps)(ComponentA);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Component B that will display movies once returned
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import {connect} from 'react-redux';

function ComponentB ({movies,loading}){
  return(
    &amp;lt;div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;h3&amp;gt;movies&amp;lt;/h3&amp;gt;
        &amp;lt;ul&amp;gt;
          {loading
            ? &amp;lt;div&amp;gt;loading ...&amp;lt;/div&amp;gt;
            :movies.map((movie,id)=&amp;gt;(
            &amp;lt;div key={id}&amp;gt;
                 &amp;lt;li &amp;gt; {movie.title} &amp;lt;/li&amp;gt;
            &amp;lt;/div&amp;gt;
          ))}
        &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

const mapStateToProps = (state) =&amp;gt; ({
  movies: state.moviesReducer.movies,
  loading: state.moviesReducer.loading
})

List.defaultProps={
  movies:[],
  loading:Boolean
}

export default connect(mapStateToProps)(ComponentB)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>redux</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Back to web development basics #1</title>
      <dc:creator>A Dev</dc:creator>
      <pubDate>Sun, 28 Jun 2020 19:51:06 +0000</pubDate>
      <link>https://dev.to/jsdev25/back-to-web-development-basics-1-1f0o</link>
      <guid>https://dev.to/jsdev25/back-to-web-development-basics-1-1f0o</guid>
      <description>&lt;h3&gt;
  
  
  This will be a series to cover basics of html &amp;amp; css
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Index
&lt;/h4&gt;

&lt;p&gt;1- Introduction&lt;br&gt;
2- HTML Elements&lt;br&gt;
3- Notes &lt;/p&gt;

&lt;h4&gt;
  
  
  1- Introduction
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This will be a series covering the basics of HTML and css for developers with basic knowledge which will take you up a notch,this is not a course.&lt;/li&gt;
&lt;li&gt;For a course try &lt;a href="https://www.codecademy.com/" rel="noopener noreferrer"&gt;Codecademy&lt;/a&gt; it has a course that was great when i tried it. &lt;/li&gt;
&lt;li&gt;Not all elements will be covered only the ones i feel necessary from my point of view to beginner developers&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2- HTML elements (sectioning elements)
&lt;/h4&gt;

&lt;p&gt;In today's post i will cover a part of the basics for HTML elements  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML have an element for every usage, meaning div is not the answer&lt;/li&gt;
&lt;li&gt;div is a general purpose element used for grouping other elements or styling&lt;/li&gt;
&lt;li&gt;there are many elements that better describe where you are and what the content will be for example:
&lt;dl&gt;
&lt;dd&gt; &amp;gt; main &lt;/dd&gt;
&lt;dd&gt; &amp;gt; section&lt;/dd&gt;
&lt;dd&gt; &amp;gt; article&lt;/dd&gt;
&lt;dd&gt; &amp;gt; aside&lt;/dd&gt;
&lt;dd&gt; &amp;gt; nav&lt;/dd&gt;
&lt;dd&gt; &amp;gt; footer&lt;/dd&gt;
&lt;dd&gt; &amp;gt; header&lt;/dd&gt;
&lt;dd&gt; &amp;gt; blockquote&lt;/dd&gt;
&lt;/dl&gt;
and sure the usual suspects p ul ol li a h1---h6
for reference check &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Breaking down elements
&lt;/h5&gt;

&lt;dl&gt;
  &lt;dt&gt; &amp;gt; main&lt;/dt&gt;
  &lt;dd&gt;main is used as a container for the main content which is directly related to your topic
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; section&lt;/dt&gt;
  &lt;dd&gt;section is used for content that can stand alone and is not proper to be used under any other element and sometimes it doesn’t make sense out of the context of the page
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; article&lt;/dt&gt;
  &lt;dd&gt;article is used when a content peace can be taken away and placed in another page and would be totally independent, think of it as an article in a news paper that can be placed on any page and it makes sense on its own
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; aside&lt;/dt&gt;
  &lt;dd&gt;aside is used for any content or info that is not related to the page content, its not certainly place on a side it might be in the middle of the page like an advertisement for example  
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; nav&lt;/dt&gt;
  &lt;dd&gt;nav is used for the navigation inside the website or to other websites whether its placed on the top or on the side as long as it holds the navigation links
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; header&lt;/dt&gt;
  &lt;dd&gt;header have to be cleared is not the head or the heading, head element is used to hold the links to css, meta, title etc... and the heading is the h1--h6 elements, but a header is the first thing presented in a page whether it holds a heading or a navigation bar or search bar, etc...
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; footer&lt;/dt&gt;
  &lt;dd&gt;footer is used at the end it usually contains information about the author, copyright data, contact information, etc... 
  &lt;/dd&gt;
___

  &lt;dt&gt; &amp;gt; blockquote&lt;/dt&gt;
  &lt;dd&gt; blockquote is to represent a quote and is given a margin from the side and placed between quotes
  &lt;/dd&gt;
&lt;/dl&gt;
 




&lt;h4&gt;
  
  
  3- General notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A header and a footer can be used inside section, article, main or whatever element you feel needs a header and a footer not only at the beginning or the ending of the body&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understanding html elements eases the reading of the code and understanding where everything stands&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next post i will discuss Forms&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
