After a prolonged struggle , Haiti became the first black republic to declare independence in 1804 .