I would like create const.js in /imports/startup/client/const.js. My content :
export const $body = document.body || document.documentElement;
export const $header = document.getElementById('js-header');
...
So, when i import my const in my /imports/ui/components/header.js :
import { $header } from '../../startup/client/const';
I've a error '$header is undefined'
Do you have any idea ?
Thank you !
Related
I have a problem to include EditorJs in my NextJs app.
I've tryed this :
Editor.js
import dynamic from "next/dynamic";
let CustomEditor = dynamic(() => import("./CustomEditor"), {
ssr: false,
});
export default function Editor() {
return (
<>
{CustomEditor && (
<CustomEditor
/>
)}
</>
);
}
CustomEditor.js
import EditorJS from "#editorjs/editorjs";
const CustomEditor = () => {
return (
<EditorJS />
);
};
export default CustomEditor;
But I have this problem :
What can I do to solve this problem?
You are not using "editor-js" correctly. Look at the docs. EditorJS is not a function/class component; thus, it can't be used. I suggest you try react editor js instead. It has pre-defined components that you can use easily as so:
import { createReactEditorJS } from 'react-editor-js'
const ReactEditorJS = createReactEditorJS()
<ReactEditorJS defaultValue={blocks} />
I'm not able to get dynamic import to work,
//event.js
import { useEffect, useRef, useState } from "react";
import dynamic from "next/dynamic";
const NoSsrLiveStreaming = dynamic(
() => import("#/components/ui/LiveStreaming"),
{
ssr: false
}
);
async function Event() {
return (
<>
<div suppressHydrationWarning={true}>
<NoSsrLiveStreaming />
</div>
</>
);
}
export default Event;
component:
//LiveStreaming.js
function LiveStreaming() {
const [appid, setAppid] = useState("");
const [token, setToken] = useState("");
const [channel, setChannel] = useState("");
let client, agoraObj;
if (isBrowser) {
client = AgoraRTC.createClient({ codec: "h264", mode: "rtc" });
agoraObj = isBrowser() ? useAgora(client) : {};
}
const {
localAudioTrack,
localVideoTrack,
leave,
join,
joinState,
remoteUsers
} = isBrowser
? agoraObj
: {
localAudioTrack: null,
localVideoTrack: null,
leave: null,
join: null,
joinState: null,
remoteUsers: null
};
It seems like it's loading the hook useLiveStream even though I disabled SSR with dynamic import.
I do have a hook in this component useAgora(client), and this hook has window objects that threw errors. That's the reason why I wrapped this around an if browser check statement.
How do i get around this?
I'm trying to create a simple component, styled with React-JSS:
import React from 'react';
import { createUseStyles, useTheme } from 'react-jss';
import { useSessionState, useSessionDispatch } from '../../../contexts/SessionContext';
const useStyles = createUseStyles({
messageSuccess: {
backgroundColor: 'green'
}
});
const SystemMessage = () => {
const dispatch = useSessionDispatch();
const theme = useTheme();
const classes = useStyles({theme});
return (
<div className={classes.messageSuccess}>
abcd
</div>
);
}
export default SystemMessage;
Upon running it, I get this message:
TypeError: Object(...) is not a function
const useStyles = createUseStyles({
What am I doing wrong?
You should update your react-css version to 10.0.0
I am new on next js and i use redux-next-wrapper !
The problem is that i want to dispatch a token access but when i am doing it in getInitialProps, the store does not update after the render of the page !
I try to use componentDidMount, it work, but the state is update only after the render of the page, which make visible the button login one second before to be replace by logout !
componentDidMount () {
const token_access = Cookies.get('xxxxxxxxxx');
const token_refresh = Cookies.get('xxxxxxxxxx');
console.log(token_access);
if (token_access && token_refresh) {
const decode = jwt_decode(token_refresh);
if (decode.exp >= new Date()) {
this.props.store.dispatch(logout(token_refresh))
}
else {
const decode_access = jwt_decode(token_access);
if (decode_access.exp >= new Date()) {
refresh(token_refresh)
}
this.props.store.dispatch(userLoggedIn(token_access));
}
}
}
static async getInitialProps ({Component, ctx}) {
const token = '12345';
ctx.store.dispatch(userLoggedIn(token));
return {
pageProps: (Component.getInitialProps ? await Component.getInitialProps(ctx) : {})
}
}
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import rootReducer from '../reducers/index'
export default initialState => createStore(
rootReducer,
composeWithDevTools(
applyMiddleware(thunk)
)
);
is there a way to dispatch and load the store before the render of the page ?
Thank you for your answer
I fix this issue by changing the store ! Hope this help someone :)
export const initStore = (initialState = {} ) => {
return createStore(rootReducer,
initialState, composeWithDevTools(applyMiddleware(thunk)))
};
This Meteor client code prints into is undefined to the console. It is expected to print the value of the info.description property passed to the composeWithTracker(composer)(Info) at the bottom of the code.
Where did I go wrong? Thanks
//--------------- carInfo.jsx ---------------
import React from 'react';
const renderWhenData = ( info ) => {
console.log( 'info is ' +info); //<<<<<<<<<<<<<<<<<<< undefined
if ( info ) {
return <span>{ info.description }</span>;
};
export let Info = ( { info } ) => (
<p>{ renderWhenData( info ) }</p>
);
//--------------- carClass.jsx ---------------
import React from 'react';
import ReactDOM from 'react-dom';
import { composeWithTracker } from 'react-komposer';
import { Info } from '../ui/carInfo.jsx';
const composer = (props, onData) => {
const subscription = Meteor.subscribe('vehicles');
if (subscription.ready()) {
const cars = Vehicles.findOne({name: 'Jack'}); //<<<<<<<<<<<<<<< document OK.
onData(null, { cars });
}
};
const Container = composeWithTracker(composer)(Info);
ReactDOM.render(<Container />, document.getElementById('react-info'));