Null Object { }
Let’s talk about null object
Ria Choi

Intro
Today I finished a feature I was excited about. Depth motion.
While wiring it up, I noticed something odd in my code. A function that does nothing. And it gets called on purpose.
I stopped and asked myself why.
The Project I've Been Working On
I'm renovating my blog. The stack is Next.js, Prisma, PostgreSQL, Docker, Resend and Sanity.
The homepage has a daisy background image. And I wanted it to feel alive.
At first, I wanted the background to be fully 3D. I planned to use Three.js, something I had been anticipating for a long, long time.
But I soon realized a problem. It would take too long to render. And I really didn't like that.
Also, I had to stack some cards on top of the background. So the 3D animation shouldn't be too eye catching anyway.
So I changed direction. I went with pixi.js to build a depth motion effect. It's the same effect you see every day on your iPhone screen.
The idea is simple. The image shifts slightly based on a depth map. Flat pixels suddenly look like they have distance.
Subtle. Light. Exactly what the page needed.
Depth Motion Tutorial Coming Soon
I will write a full tutorial on how I built it. It uses pixi.js and a displacement filter.
This post is about one small thing I found along the way.
The Code
Here is the part that caught my eye. I trimmed it to the important lines.
useEffect(() => {
let dispose = () => {};
function sync() {
dispose();
// ...set up the effect...
dispose = cleanupInstance;
}
sync();
}, []);
Look at the first line. dispose starts as an empty function.
Then sync() calls dispose() right away. Before anything exists.
Why Call an Empty Function?
My first thought was simple.
‘Why call a function that does nothing?’
Here is the answer. sync() runs every time the screen size or device type changes. Each run must clean up the previous one first.
But the very first run has nothing to clean up.
Without the empty function, I would need a check:
if (dispose) {
dispose();
}
With the empty function, I just call dispose(). It is always safe. On the first run it does nothing. On later runs it does real cleanup, because I replace it with cleanupInstance.
No checks. No crashes. Cleaner code.
What Is a Null Object?
A Null Object is a stand in that does nothing.
Instead of using null or undefined to mean "nothing here," you use a real object that has the same shape but safe, empty behavior.
My () => {} is a tiny version of this idea. To be precise, the classic pattern uses an object with methods. Mine is a no op function. But the thinking is the same.
Why Use a Null Object?
There are a few good reasons.
- Fewer checks. You skip if (x) before every call.
- Fewer bugs. Calling null() throws an error. Calling an empty function does not.
- Cleaner flow. The code reads in one straight line.
- Safe defaults. Something always exists, so nothing breaks at the start.
It is a small trick. But it removes a lot of noise.
Final Thoughts
I almost deleted that empty function. I'm glad I asked why it was there first.
Next time, I'll share the full depth motion tutorial. See you then.

