我在 Heroku 上部署了 Rails + Tailwind 应用程序,但失败并出现以下错误。
SassC::SyntaxError: Error: Function rgb is missing argument $green.
on line 607 of stdin
>> color: rgb(239 68 68 / var(--tw-text-opacity));
Run Code Online (Sandbox Code Playgroud)
以下是我将 Tailwind 安装到应用程序的方法。
bin/bundle add tailwindcss-rails
bin/rails tailwindcss:install
Run Code Online (Sandbox Code Playgroud) 我想更新子组件中的状态,但它不起作用。实际上,有很多项目。我想列出每个项目map。
错误:
React Hook "useState" 不能在回调中调用。React Hooks 必须在 React 函数组件或自定义 React Hook 函数中调用
编码:
const renderItems = useCallback(() => {
return items.map((item, idx) => {
const { name } = room
const [isCopiedURL, setIsCopiedURL] = useState(false)
return (
<li key={idx}>
<CopyToClipboard
text={item.name}
onCopy={() => setIsCopiedURL(true)}
>
{item.name}
</CopyToClipboard>
</li>
)
})
}, [items])
Run Code Online (Sandbox Code Playgroud) 我正在使用 Cloud Firestore 开发 React 项目。我已成功从 Firestore 获取数据。但我无法将这些数据设置为state。
我如何设置状态这些数据。
class App extends Component {
constructor(props) {
super(props);
this.state = {
items: []
};
}
async componentDidMount() {
const items = [];
firebase
.firestore()
.collection("items")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
items.push(doc.data());
});
});
this.setState({ items: items });
}
render() {
const items = this.state.items;
console.log("items", items);
return (
<div>
<div>
<ul>
{items.map(item => (
<li>
<span>{item.name}()</span>
</li>
))}
</ul>
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud) 我在我的React项目中使用Firebase。用户尚未登录时,应用程序无法重定向到“登录”页面的问题。
在“我Home.js拥有”页面中,该页面仅允许已登录应用程序的用户使用。
class Home extends React.Component {
constructor(props) {
super(props);
}
logout = () => {
firebase.auth().signOut();
this.props.history.push("/login");
};
render() {
if (firebase.auth().currentUser === null) {
return <Redirect to="/login" />;
}
return (
<div>
<div>
<Button variant="contained" color="primary" onClick={this.logout}>
Google Logoout
</Button>
</div>
</div>
);
}
}
export default withRouter(Home);
Run Code Online (Sandbox Code Playgroud)
实际上,我用于通过分类用户是否登录firebase.auth().currentUser。
我想通过每天安排一次来“导出 Firestore 数据”。这是firebase 官方文档。我尝试过,但它不起作用,因为出现以下错误:
无法读取未定义的属性“toString”
代码:
const functions = require('firebase-functions')
const firestoreClient = require('@google-cloud/firestore')
const admin = require('firebase-admin')
admin.initializeApp()
const firestore = admin.firestore()
//------------------------------------------------------
// backup
//------------------------------------------------------
const client = new firestoreClient.v1.FirestoreAdminClient()
exports.scheduledFirestoreExport = functions.pubsub
.schedule('every 24 hours')
.onRun(() => {
const databaseName = client.databasePath(
process.env.GCP_PROJECT,
'(default)',
)
const bucket = 'gs://backups-firestore'
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
collectionIds: [
'users',
],
})
.then((responses) => {
const response = responses[0]
console.log(`Operation Name: ${response['name']}`)
return response
})
.catch((err) …Run Code Online (Sandbox Code Playgroud)