Closed alecdiaz1 closed 3 years ago
Are you sure that you built it correctly? Using the build:resources
comand
Yeah, I'm running build:resources
and my changes appear (just leaving the app always visible). This is also my first time making a FiveM resource so maybe there's something simple that I'm missing?
I also tried logging when useNuiEvent
receives an event but I haven't been able to see any event being received when I run /show:nui
. But the message show:nui run!
appears in chat.
cl_main.lua
RegisterCommand('show:nui', function(source, args, rawCommand)
SendNuiMessage({
app = "REACTNUI",
method = "setVisibility",
data = true,
})
SendNuiMessage({
app = "newspaper",
method = "testFunc",
data = 'test message',
})
TriggerEvent('chat:addMessage', {
args = { 'show:nui run!' }
})
end, false)
useCoreService.ts
import { useSetRecoilState } from 'recoil'
import { useVisibility } from './useVisibility'
import { coreState } from './state'
import { useNuiEvent } from 'fivem-nui-react-lib'
export const useCoreService = () => {
const setShowHide = useSetRecoilState(coreState.visibility)
// You can change these strings to whatever you wish :)
useNuiEvent<boolean>('REACTNUI', 'setVisibility', setShowHide)
useNuiEvent('newspaper', 'testFunc', (msg) => console.log(`${msg} ---- msg`))
return useVisibility()
}
@alecdiaz1 Thanks for the issue. I'll look into this today, to see if I can replicate.
EDIT: Can you open your nui_devtools in-game, and then if if the html body as been populated?
@alecdiaz1 This might be my fault...
Check if the resource
prop on the NuiProvider
, in the index.tsx file is the same to whatever your resource is called :D
@itschip I can confirm that the html body is populated, removing the div that controls visibility, the UI pops up in game (but automatically on starting resource, not through command). The resource prop is also set to the name of my resource.
Here's the commit I'm working off of. Commits after that I removed the core hooks and handled the Nui messages on my own though.
Oh fuck me.... its SendNUIMessage, not SendNuiMessage. Try that
Edit: check the natives documentation for this :P
@itschip 🤦♂️ Haha yep it was the SendNuiMessage
being that instead of the correct SendNUIMessage
. I believe cl_main.lua
needs to be updated to fix that then?
Yup, it needs an update indeed :)
@alecdiaz1 Fixed now!
I think I've installed it correctly, if I remove the
style={ visibility ? { visibility: 'visible' } : { visibility: 'hidden' }}
from the div inApp.tsx
the content shows up on the screen. But doing/show:nui
doesn't seem to toggle the nui visibility. I can confirm that the command is being triggered as I can send a message to chat when I run the command. It's just the visibility doesn't seem to toggle.