Hello, I'm Stanko, a software engineer in Belgrade, writing mostly about JavaScript and React.

My programming story

This was intended to be a single paragraph in the post I’m still writing. It ended up much longer so I decided to publish it on it’s own. So without further due, I present you my programming story.

Read more

Consume less, create more

That’s my new year’s resolution. Code, write, play and craft more!

Get scrollbar width in JavaScript

2 Comments

Another onliner I love, that returns body scrollbar width. If scrollbar is not shown it will return zero (including mobile devices).

function getScrollbarWidth() {
  return window.innerWidth - document.documentElement.clientWidth;
}

Click on the button to try it yourself:

Browser support

Tested on:

  • Windows: IE9, IE10, IE11, Edge
  • MacOS: Safari, Firefox, Chrome, Opera
  • iOS: Safari, Chrome
  • Android: Chrome

Simple JavaScript API wrapper

3 Comments

For handling API calls I have a small snippet I’m copying from project to project. I decided to clean it up, make more generic and share it. It is intended to be a starting point, so you might want to customize it to your custom needs.

What it does?

It is a simple wrapper around If you need a polyfill isomorphic-fetch is a great one.

  • For successful requests it will parse the response and return it.
  • When It detects errors based on request’s HTTP status. it will throw a custom error with status code, error message and response (parsed if it is a JSON).
  • If request never gets resolved, same custom error will be thrown but response will be set to null and status code to REQUEST_FAILED.

Please note that function will return a Promise so you need to handle how it resolves.

Read more

React Window decorators

Two days ago I released two npm packages, window-scroll-manager and react-window-decorators.

Scroll manager

Plx uses the same scroll manager so I extracted it to the standalone package. is just a simple wrapper around scroll event, that broadcasts custom window-scroll event once per requestAnimationFrame. Idea comes from MDN.

React decorators

or higher order components are the bees knees, as they bring easy way to track window scroll and resize events in React. They will track and inject props directly into React components. Check the demo.

Read more