<?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: Tahmina Nasrin Tazin</title>
    <description>The latest articles on DEV Community by Tahmina Nasrin Tazin (@tazinnn).</description>
    <link>https://dev.to/tazinnn</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%2F780460%2Fc179ebea-4dab-4560-bea9-0c077b887e2f.jpeg</url>
      <title>DEV Community: Tahmina Nasrin Tazin</title>
      <link>https://dev.to/tazinnn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tazinnn"/>
    <language>en</language>
    <item>
      <title>MongoDB CRUD Operations</title>
      <dc:creator>Tahmina Nasrin Tazin</dc:creator>
      <pubDate>Tue, 28 Dec 2021 08:33:43 +0000</pubDate>
      <link>https://dev.to/tazinnn/mongodb-crud-operations-540l</link>
      <guid>https://dev.to/tazinnn/mongodb-crud-operations-540l</guid>
      <description>&lt;p&gt;MongoDB is a NoSQL database program that is a document-oriented database program. It has gained popularity as NoSQL databases are handy for working with large sets of data. Simple CRUD operations have been described below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt;&lt;br&gt;
To insert a single document, the insertOne() method can be used. The document object to be inserted has to be passed as the argument. If the insertion is successful, an insertedId field is appended to the object passed in the method. This value is used as the _id in the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      const newProduct = {
    name: ‘Flormar Lipstick’,
    price: ‘45.00’,
}
      const result = await lipsticksCollection.insertOne(newProduct);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Retrieve&lt;/strong&gt;&lt;br&gt;
To retrieve a single document, the findOne() method can be used. The document to be searched has to be queried and the query has to be passed as the argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = req.params.id;
      const query = { _id: ObjectId(id) };
      const product = await lipsticksCollection.findOne(query);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;br&gt;
To update a single document, the updateOne() method can be used. A filter document and an update document has to be passed as argument. The purpose of the filter document is to find the document to be updated. A third argument named options can be passed as well to specify any other options if needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = req.params.id;
      const filter = { _id: ObjectId(id) };
      const options = { upsert: true };

      const updateDoc = {
        $set: {
          status: "Shipped",
        },
      };
      const result = await ordersCollection.updateOne(
        filter,
        updateDoc,
        options
      );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Delete&lt;/strong&gt;&lt;br&gt;
To delete a single document, the deleteOne() method can be used. The document to be deleted has to be queried and the query has to be passed as the argument. If the deletion is successful, then the deletedCount is set to 1, which can be checked to test whether the operation was successful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = req.params.id;
      const query = { _id: ObjectId(id) };
      const result = await lipsticksCollection.deleteOne(query);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>mongodb</category>
      <category>beginners</category>
      <category>database</category>
    </item>
    <item>
      <title>React Hooks</title>
      <dc:creator>Tahmina Nasrin Tazin</dc:creator>
      <pubDate>Tue, 28 Dec 2021 08:19:29 +0000</pubDate>
      <link>https://dev.to/tazinnn/react-hooks-1n0i</link>
      <guid>https://dev.to/tazinnn/react-hooks-1n0i</guid>
      <description>&lt;p&gt;Hooks are simply functions that allow us to add lifecycle features and states to functional components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules of Hook
&lt;/h2&gt;

&lt;p&gt;There are two rules that must be followed when working with Hooks&lt;br&gt;
Hooks should always be called at the top level. Hooks should not be called inside loops, conditions, or nested functions. This is to ensure that after every render of the components, the Hooks are called in the same order every time.&lt;br&gt;
Hooks can only be called from React functions. Hooks cannot be called from regular JavaScript functions. Therefore, they can be called from functional components and from custom Hooks.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Hooks
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;useState&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, setState] = useState(initialState);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hook is used to add states to functional components. Using the initialState argument, we can provide an initial state if needed. The hook returns the current state and a function that is used to update the state. If the state is updated, the component is re-rendered.&lt;/p&gt;

&lt;p&gt;For naming the state and its updating function, the common convention that is followed is [something, setSomething].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt;&lt;br&gt;
This hook is used to perform side functions in the components, such as fetching data, subscription set up etc. It is used to make the component do something right after rendering. It runs after every render by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(()=&amp;gt; {
// some code }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The optional second argument is so that the component re-renders only if the value of that argument has changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useContext&lt;/strong&gt;&lt;br&gt;
This hook is useful in avoiding prop drilling as it allows to manage states globally. The components can be re-rendered when these global states change. &lt;/p&gt;

&lt;p&gt;First, the context has to be created and initialized. Then the child components have to be wrapped in the Context Provider and the state value has to be supplied.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserContext = createContext()
function Component1() {
  const [user, setUser] = useState("Jesse Hall");

  return (
    &amp;lt;UserContext.Provider value={user}&amp;gt;
      &amp;lt;h1&amp;gt;{`Hello ${user}!`}&amp;lt;/h1&amp;gt;
      &amp;lt;Component2 user={user} /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, the user Context will be accessible in all the components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom Hooks
&lt;/h2&gt;

&lt;p&gt;React also gives us the option to create our own hooks according to our needs. We may need custom hooks when we have a reusable function. The custom Hook’s name must start with “use”. Example: useStatus.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
