GithubHelp home page GithubHelp logo

rwieruch / blog_robinwieruch_content Goto Github PK

View Code? Open in Web Editor NEW
314.0 20.0 384.0 80.5 MB

✏️ Content of robinwieruch.de - Write guest blog posts or improve the content. Your help means a lot to me.

Home Page: https://www.robinwieruch.de/

JavaScript 98.67% Shell 0.18% SCSS 1.16%
react reactjs javascript web-development

blog_robinwieruch_content's Introduction

Content & Contribution

A place where you can actively contribute to robinwieruch.de.

  • Improve any blog post by editing the file directly in this GitHub repository.
  • Write a new guest blog post by creating a new file in this GitHub repository and follow the "Guidelines for Guest Bloggers" below. Get in touch with me before you start writing an entire article :)

Guidelines for Guest Bloggers

Folder/Files

Just create a new folder for your blog post. The folder's name will be the URI for the blog post. In this folder, you can create your markdown file with the text and use images from a folder next to it:

my-blog-post/
-- index.md
-- images
---- my-image.jpg

Frontmatter

You can leave out all the frontmatter (e.g. title, description) that I use for my blog posts. I can add these later myself.

Code

Don't use images for code. Instead use a code snippet the following way:

```javascript
const helloWorld = "Hello World!";
```

If you want to highlight changes in the code, that's what I usually do in my tutorials, then you can do it by providing the numbers of lines you want to highlight:

```javascript{3}
const helloWorld = "Hello World!";

console.log(helloWorld);
```

If you move around from file to file in your tutorial, don't forget to mention the place where you edit/create the next code snippet. Something like:

Now we are going to implement user model in the src/models/user.js file:

```javascript
const user = createModel('user');
```

Images

Don't use images for code. Instead use code snippets. If you want to have images in the blog post, add them in at least 1024x768 resolution preferable in .jpg. In the article, reference the image with a proper alt text:

![my image alt text](./images/my-image.jpg)

Image files are placed next to the blog post's markdown file.

Command Line vs. GUI

There are many tutorials out there that are using lots of images to show a GUI where they do their configuration. I'd like to use as few images as possibles and encourage people to use more often their command line instead. If the a GUI needs to be shown, then an image can be used though.

Code Formatting

I use Prettier in my projects which helps me to keep all my code snippets equally formatted for my tutorials. That's my default configuration:

{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 70
}

Headlines

  • h1 headline translates to # My Headline in markdown
  • h2 headline translates to ## My Secondary Headline in markdown

My articles usually follow the same structure with optional ## Secondary Headlines in between:

Be clear about the motivation of this article ...

# My Headline

# My other Headline

## My Secondary Headline

<Divider />

Outro

Links

Links can be used the following way:

[my article name](url)

Italics

I usually use italics with * for folders and files like src/models/user.index/js or src/.

Bold

I usually use bold with ** to point out the importance of something or to highlight a specific topic in a paragraph.

blog_robinwieruch_content's People

Contributors

abraj avatar benjamminj avatar bogdanbacosca avatar breyman avatar briantomillo avatar cfleschhut avatar christianboyle avatar dasenkiv avatar dkris avatar emmanuelstalling avatar jaimemendozadev avatar jarrad-obrien avatar jyuen avatar ma-nish avatar maelfr avatar mangopomelo avatar nicoder avatar omarnaguib avatar ossan-engineer avatar pavanmehta91 avatar peterhauke avatar ririyad avatar rossolson avatar rwieruch avatar sydinh avatar tomaslau avatar trevorgk avatar troywolf avatar umungobungo avatar vitya-ne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blog_robinwieruch_content's Issues

Changes in Webpack make the suggested configurations throw an error (Adding imports-loader exports-loader)

When we are adding Fetch and imports-loader and exports-loader to the project, the tutorial suggests to add the following configuration to 'webpack.config.js' :
plugins: [ new webpack.ProvidePlugin({ 'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch' }) ]
But if you try to start the project you get an error. The problem is that WebPack's new version doesn't support to omit the '-loader' suffix.

The working configuration for me ended up like this:
plugins: [ new webpack.ProvidePlugin({ 'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch' }) ]

Security

Really great article! One concern I have is that (e.g. on Safari you can view the source using the Develop Menu -> Show Page Source) anyone can read your Firebase configuration details e.g. api key and project id. Is this enough information to allow people to hack into your Firebase service?

Minor inconvenience: routes used in SignUp.js before being imported.

routes is not defined before being used in <Link to={routes.SIGN_UP}>Sign Up</Link>, making the code unable to compile while working through SignUpForm. Not sure if better to just leave the SignUpLink out first or just import routes at the start.

Edit: Whoops, this is for "A Complete Firebase in React Authentication Tutorial".

Change header image

I am unsure what a woman dressed in scant armor next to a tiki torch has to do with web components.

Please consider a more inclusive image

Sequelize and Webpack not playing nice together

I have to say, this tutorial is a godsend. I love the breakdowns and very clear-cut explanations and I just so happen to need to use most of the packages.

I was following the guide fairly well until the Sequelize part of the tutorial and I was getting an error: "Cannot find module C:\PROJECT_DIR\\.webpack\service\src\user" for the user file. I've tried the following:

const models = [ 'User', 'Message' ];

models.forEach(function(model) { module.exports[model] = sequelize.import(__dirname + '/' + model); });

But when I ran it again, "Cannot find module 'C:\User'"

  1. Sequelize as a nodeExternal

  2. Adding this piece to webpack.config.js
    node: { __dirname: false },

Error: "Cannot find module C:\PROJECT_DIR\\.webpack\service\src\user"

  1. There has been some examples around google such as https://gist.github.com/ihavenoidea14/0dab8b461c057c427829fdc99bfb6743
    webpack/webpack#4879

that uses module(sequelize, Sequelize); When I tried the examples in the links above, I get a 'module is not a function'.

I'm at a loss and am wondering if you had tried with Webpack before and if you have any recommendations I'd love to hear it.

Cheers.

Changes in Webpack make the suggested configurations throw an error (Adding Babel)

When we are adding Babel to the project, the tutorial suggests to add the following configuration to 'webpack.config.js' :
module: { loaders: [{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'react-hot!babel' }] }, resolve: { extensions: ['', '.js', '.jsx'] },
But if you try to start the project you get an error. The problem is that WebPack's new version doesn't support providing empty extensions, and also the '-loader' part of libraries cannot be skipped.

The working configuration for me ended up like this:
module: { loaders: [{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'react-hot-loader!babel-loader' }] }, resolve: { extensions: ['.js', '.jsx'] },

why-graphql-advantages-disadvantages-alternatives missing disadvantages

Hi I read https://www.robinwieruch.de/why-graphql-advantages-disadvantages-alternatives/

I think it is well written, however I think It is missing a disadvantage or two.

How to send and read binary data ? With graphql the answer is not so clear, base64 encoding decoding, multipart data, extension ?

Client side and server side overhead Runtime overhead compared to simple regular REST, also load time overhead to load the graphql on the client side.

Avoiding trying try/catch block when handling errors in Express?

Hi

I was reading this blog ( https://github.com/rwieruch/blog_robinwieruch_content/blob/master/blog/node-express-error-handling/index.md ) about the handling errors in Express JS. Before sharing my note, I want to thank you for your efforts.

When you said: Fortunately we don't need to use a try/catch block but just use the promise's catch method instead.

router.post('/', async (req, res, next) => {
  const message = await req.context.models.Message.create({
    text: req.body.text,
    user: req.context.me.id,
  }).catch(next);

  return res.send(message);
});

I think that this is not correct. When the middleware finishes sending the error to the client, Express will try to run res.send(message). This will raise another exception because the code is trying to send another response to the client.
please correct me if I'm wrong.
Here's a copy of the error :

node:internal/process/promises:245
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:329:5)
    at ServerResponse.setHeader (node:_http_outgoing:579:11)
    at ServerResponse.header (/home/.../node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/home/.../node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/home/.../node_modules/express/lib/response.js:267:15)
    at eval (webpack:///./src/controllers/users.js?:34:18)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async createUser (webpack:///./src/controllers/users.js?:31:3) {
  code: 'ERR_HTTP_HEADERS_SENT'
}
[nodemon] app crashed - waiting for file changes before starting...

I think the correct way to do it, is wether by using try/catch block or by moving the res.send into then before the catch block, it should look like:

router.post('/', async (req, res, next) => {
  req.context.models.Message.create({
    text: req.body.text,
    user: req.context.me.id,
  }).then(()=>res.send(message))
  .catch(next);
});

The same thing for the following code.

...

import { BadRequestError } from '../utils/errors';

...

router.post('/', async (req, res, next) => {
  const message = await req.context.models.Message.create({
    text: req.body.text,
    user: req.context.me.id,
  }).catch((error) => next(new BadRequestError(error)));

  return res.send(message);
});

Typo.

How to set up an advanced Webpack application

index.md: line 19 last sentence

Make sure to give it a start if you like it.

I'm I missing something or it is a typo?

Capture Payment Later

I want to only authorize my payment first and payment-capture will be done later. But, upon trying with my current code, the sandbox account that I use, displays all the transactions as 'completed'. What do I do to only 'authorize' my payment and not capture it? This is my code:

render() {
    const {
        total,
        currency,
        env,
        commit,
        client,
        onSuccess,
        onError,
        onCancel,
      } = this.props;
  
      const {
        showButton,
      } = this.state;
  
      const payment = () =>
      paypal.rest.payment.create(env, client, {
        transactions: [
          {
            amount: {
              total,
              currency,
            }
          },
        ],
      });
const onAuthorize = (data, actions) =>{
      actions.payment.execute()
          .then(() => {
            onSuccess(data,actions);
        });
      }
  
      return (
        <div>
          {showButton && <paypal.Button.react
            env={env}
            client={client}
            commit={commit}
            payment={payment}
            onAuthorize={onAuthorize}
            onCancel={onCancel}
            onError={onError}
          />}
        </div>
      );
    }

I think this tutorial might be out of date

I tried to follow this tutorial but get stuck at this step.

<FirebaseContext.Provider value={new Firebase()}>

It produces an error that says:

TypeError: components_firebase_index_jsx__WEBPACK_IMPORTED_MODULE_5_.default is not a constructor

Others on stack overflow have commented that Google Auth is no longer configured the way it once was and that this may be the reason that the tutorial steps aren't producing the expected outcomes.

Have others found a way through this?

No next method or return value in the useReducer + middleware example

In the this example, currently, the middleware does not take in account two important aspects of middlewares:

  1. the next method
  2. the return value mechanism

The next method enables you to break the middleware chain in certain circumstances.
The return value mechanism allows you to bubble up promises or return values to the entity which invoked the dispatch method.

How to use React Testing Library Tutorial: aways act() warning

Hi Robin, I am learning RTL by reading your aritlce How to use React Testing Library Tutorial.

When I write this test example:

import React from 'react';
import { render, screen } from '@testing-library/react';
 
import App from './App';
 
describe('App', () => {
  test('renders App component', async () => {
    render(<App />);
 
    expect(screen.queryByText(/Signed in as/)).toBeNull();
 
    screen.debug();
 
    expect(await screen.findByText(/Signed in as/)).toBeInTheDocument();
 
    screen.debug();
  });
});

There is aways Warning:

    console.error
      Warning: An update to App inside a test was not wrapped in act(...).
      
      When testing, code that causes React state updates should be wrapped into act(...):
      
      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */
      
      This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
          in App

I have googled for the reason and solution, but I have added await in the code.

Do you have any solutions please ?

Yet another use case for fetch()

Super nicely written article.
Unfortunately, I had to resolve my issues long before I saw it...
The use case that is missing is "loading over 100 items" as is the case with REST-API.

It is interesting how you resolve the async. behavior in two main scenarios:

  1. You need all data prior to rendering & you want single setState() call
  2. Ways to perform async. so to provide response & rendering faster

Typo. webpack-advanced-setup-tutorial

const HtmlWebpackPlugin = require('html-webpack-plugin')
 
module.exports = {
  ...
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Hello Webpack bundled JavaScript Project',
      template: './src/index.html'
    })
  ],
  ...
};

Isn't the template supposed to be template: './dist/index.html' because our html file is in the dist folder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.