Update index.js

Run leave hook on previous state before enter on next