My team is attempting to migrate our app over to styled-components, but we still have a lot of variables defined in our sass files. I have managed to send our sass variables through a sass function, and then return them in our React as a string using window.getComputedStyle().
The problem is that I cannot JSON.parse() the string even though it is formatted as json. Is there anyway to pass JSON from sass to React/Javascript?
Sass:
@function export-vars(){
@return "{'$theme-color': ' #3A82C3 !default'}";
}
body::before {
content: export-vars();
}
React:
useEffect(() => {
const tmp = window.getComputedStyle(document.body, '::before')
console.log(typeof tmp)
console.log(tmp)
})