Gutenberg get index of gutenberg innerblock

You may now retrieve the index of a inner block via the core/block-editor data module. You may pair it with the useSelect hook to keep the indexes up to date on changes.

Something like this. Intentionally verbose for clarity.

import {useSelect} from '@wordpress/data';

const Answer = ( blockProps ) => {
    const {index} = useSelect( select => {
        const {getBlockIndex} = select( 'core/block-editor' );
        return {
            index: getBlockIndex( blockProps.clientId );
        }
    } );

    return ( <li {...blockProps}>
        <input id="checkbox-2" type="checkbox" value="checkbox-2" />
        <label className="checkbox" htmlFor="checkbox-2">
            {JSON.stringify( blockProps.attributes )}
            {index}
            <span className="quiz--answer-content">{blockProps.attributes.explanation}</span>
        </label>
    </li> );
}